Version trouble at handlebar-rust

This has me puzzled. I'm building something that uses "handlebars" from within a dependency that's not mine. It's pulling in handlebars 5.1.2, which is current. Fails to compile with error:

error[E0599]: no method named `message` found for enum `ErrorVariant` in the current scope
   --> /home/john/.cargo/registry/src/index.crates.io-6f17d22bba15001f/handlebars-5.1.2/src/template.rs:644:27
    |
644 |                 e.variant.message().to_string(),
    |                           ^^^^^^^ method not found in `ErrorVariant<Rule>`

This is a version problem. ErrorVariant is from crate "pest", and only newer versions of ErrorVariant have message() as a method. In earlier versions, it was a field.

So, time to look at cargo.lock and cargo.toml files.
Version of "handlebars" pulled in is 5.1.2. Current.
Version of "pest" pulled in is "2.1.3". Not current; current in cargo.io is 2.7.9.

Checking "handlebars" Cargo.toml: pest = "2.1.3" That old version of "pest" doesn't have .message(), so handlebars won't compile.

So far, it just looks like a botched dependency.

So, to reproduce the problem for a bug report, I build "handlebars" from

git clone https://github.com/sunng87/handlebars-rust.git

That builds fine. When I look at its Cargo.lock file, I find

[[package]]
name = "pest"
version = "2.7.9"

Why did Cargo pick that later version, when the Cargo.toml file for "handlebar-rust" has

pest = "2.1.0"

Not seeing any workspace-level files or overrides.

Cargo considers that versions are equivalent if their left-most non-zero number is the same - see here:
https://doc.rust-lang.org/cargo/reference/resolver.html#semver-compatibility

So if Cargo.toml says "2.1.0", but "2.7.9" is available, Cargo would go for "2.7.9".

What happens if you run cargo update on your project

Oh, right. Default is not "="

It works. I forgot that I'd started from a branch of an existing checkout, not a new checkout.

Does that mean pest's 2.7.9 (or something between that and 2.1.3) is a breaking change?

Or if it's strictly additional and doesn't break existing code, did handlebars fail to notice that they relied on a new feature and bump their dependency version of pest accordingly?

What can we do to avoid (as authors of our own crates) that kind of problem in the future?

This. It it a kind of change for which Semver uses minor version bump, and here minor version have indeed changed.

Possible way is to check regularly with something like cargo-minimal-versions.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.