A bug for shards command?

I want to try snappy shards which write by @naqvis .

so, i create a new app from scratch, with only following dependencies add into shards.yml

dependencies:
  snappy:
    github: naqvis/snappy

When i run shards install -vvvv, i get following error:

 ╰─ $ shards install -vvvv
Resolving dependencies
Fetching https://github.com/naqvis/snappy.git
Error in snappy:shard.yml: could not find expected ':' at line 6, column 1, while scanning a simple key at line 4, column 1

  4. Snappy compression format reader/writer for Crystal
  5.
  6. authors:
     ^

Which come from snappy’s shards.yml, but, i don’t think this yaml format exists any issue.

 ╰─ $ curl -L https://raw.githubusercontent.com/naqvis/snappy/master/shard.yml
name: snappy
version: 0.1.7
description: |
  Snappy compression format reader/writer for Crystal
authors:
  - Ali Naqvi <syed.alinaqvi@gmail.com>

crystal: ">= 0.36.0, < 2.0.0"

license: MIT

I built shards from 29123fc, which should be the tag v0.17.4.

Thanks.

The error doesn’t come from the most recent shard.yml, but the version in an older release, v0.1.0:

You can also see in the error message the missing indent on the description body line.

So while it’s totally expected for shards to refuse parsing this version of the file, it does a really bad job about handling it.

  • The error message should be more detailled and include information about the version of this file. This would make it easier to find out the reason.
  • An error while parsing one version of a shard should not crash the entire process. It would be totally fine to notify about the error and continue with dependency resolution, simply ignoring the faulty version.

The error doesn’t come from the most recent shard.yml, but the version in an older release, v0.1.0:

now that, we are not reference 0.1.0 as version in my shards.yml, why shards raise this error?

The dependency resolver takes all versions into account to solve the dependency graph.

Yet another reason why I think the behavior of “pick the latest release” default logic is a foot gun. You totally avoid this problem and make it more clear what’s happening if you actually declare the version you want: version: ~> 0.1.7. Tada :tada:.

1 Like

Yes, i tested, specified a version work.

The dependency resolver takes all versions into account to solve the dependency graph.

But, the latest release tagged version always is a good default instead check all version, otherwise, for issue like snappy, it is unreasonable to expect the shards author to force update its old version of the tag.

Pretty sure it has to check all versions, because what if the latest one has a dependency that conflicts with a dependency in your shard.yml. E.g. you require 0.x.x and the latest release of a shard requires 1.x.x. “Latest compatible release” would be more accurate.

I suppose the dependency graph could be constructed in a way that it first tries like more recent versions and if that works out, there’s no need to look at older ones.
This would be a major change to the dependency resolution algorithm and probably not very feasible.