Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle cargo version conflicts #3213

Merged
merged 6 commits into from
Mar 4, 2021

Conversation

xlgmokha
Copy link
Contributor

@xlgmokha xlgmokha commented Mar 1, 2021

Why is this needed?

This addresses a failure that occurs when two direct cargo dependencies have
conflicting constraints against a common indirect dependency.

What does this do?

This change pushes down a line that raises an error before the check
for a version constraint conflict has occurred.

Fixes https://github.com/github/dependabot-updates/issues/1104

Before:

[dependabot-core-dev] ~/dependabot-core $ ./bin/dry-run.rb cargo djc/template-benchmarks-rs --cache=files --dep=ructe
=> reading dependency files from cache manifest: ./dry-run/djc/template-benchmarks-rs/cache-manifest-cargo.json
=> parsing dependency files
=> updating 1 dependencies: ructe

=== ructe (0b8acfe5eea15713bc56c156f974fa05967d0353)
 => checking for updates 1/1
 => latest available version is acbe090356c7964123eba5d25f3437f31944cfc3
 => handled error whilst updating ructe: dependency_file_not_resolvable {:message=>"Updating git repository `https://github.com/kaj/ructe`\n    Updating crates.io index\nerror: failed to select a version for `nom`.\n    ... required by package `ructe v0.13.1-PRE (https://github.com/kaj/ructe#acbe0903)`\n    ... which is depended on by `template-benchmarks-rs v0.1.0 (/home/dependabot/dependabot-core/dependabot_tmp_dir)`\nversions that meet the requirements `^6.1.0` are: 6.1.2, 6.1.1, 6.1.0\n\nall possible versions conflict with previously selected packages.\n\n  previously selected package `nom v6.0.1`\n    ... which is depended on by `askama_shared v0.11.1 (https://github.com/djc/askama?branch=main#bc2e92e7)`\n    ... which is depended on by `askama v0.10.5 (https://github.com/djc/askama?branch=main#bc2e92e7)`\n    ... which is depended on by `template-benchmarks-rs v0.1.0 (/home/dependabot/dependabot-core/dependabot_tmp_dir)`\n\nfailed to select a version for `nom` which could resolve this conflict"}

After:

[dependabot-core-dev] ~/dependabot-core $ ./bin/dry-run.rb cargo djc/template-benchmarks-rs --cache=files --dep=ructe
=> reading dependency files from cache manifest: ./dry-run/djc/template-benchmarks-rs/cache-manifest-cargo.json
=> parsing dependency files
=> updating 1 dependencies: ructe

=== ructe (0b8acfe5eea15713bc56c156f974fa05967d0353)
 => checking for updates 1/1
 => latest available version is acbe090356c7964123eba5d25f3437f31944cfc3
 => latest allowed version is 0b8acfe5eea15713bc56c156f974fa05967d0353
 => requirements to unlock: update_not_possible
 => requirements update strategy: bump_versions
    (no update possible 🙅‍♀️)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

@xlgmokha xlgmokha changed the title test: add test to reproduce described defect Gracefully handle cargo version conflicts Mar 1, 2021
@xlgmokha xlgmokha force-pushed the updates/issues/1104-rust-issues branch from 0c5be18 to 38ff4e0 Compare March 1, 2021 20:55
@xlgmokha xlgmokha marked this pull request as ready for review March 1, 2021 22:55
@xlgmokha xlgmokha requested a review from a team as a code owner March 1, 2021 22:55
@xlgmokha
Copy link
Contributor Author

xlgmokha commented Mar 2, 2021

Are there additional steps to take to test this against test projects in the dsp-testing org?

maud = { git = "https://github.com/lambda-fairy/maud" }

[build-dependencies]
ructe = { git = "https://github.com/kaj/ructe" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering, could we cut this down to just ructe and askma which seem to have the conflicting deps? Had a go at testing this locally and the first time the test ran it took over 2 mins to run so might be due to the large poject

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. I remember you mentioned that we should whittle this down to just the important bits. I'll try to reduce this and the .lock file to just the relevant bits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, you might be able to just edit the Cargo.toml and run cargo generate-lockfile

@@ -237,6 +235,8 @@ def handle_cargo_errors(error)
return nil
end

raise Dependabot::DependencyFileNotResolvable, error.message if resolvability_error?(error.message)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the right thing considering all existing specs pass but can't say I understand what all possible versions conflict actually means 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping that a failing test would guide me. I quick dive into the history lead me to a PR where the rubocop rule for line length changed from 80 to 120. I didn't go deeper than that. I'll do a deeper dive and see what source of additional context that I can discover.

Copy link
Contributor

@feelepxyz feelepxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together and sorry for the slow review, got swamped by the bundler work.

I think this change makes sense and existing tests pass so 👍 on the change. I think the way we'll gain confidence in cargo is by making more changes and responding to issues that crop up.

Just had a comment about slimming down the test fixtures if possible, wouldn't spend ages on it but if it would work by just removing all deps except ructe and askma seems like it could speed up tests a fair bit?

@feelepxyz
Copy link
Contributor

Are there additional steps to take to test this against test projects in the dsp-testing org?

I would usually trust tests and dry-runs for these kinds of changes. Testing it end to end in staging would add hours to the rollout right now 😬

You could test the repo in question with: bin/dry-run.rb cargo "repo/name" --cache=files if it's public and see how the updater would handle it.

@xlgmokha xlgmokha force-pushed the updates/issues/1104-rust-issues branch from 760fc9b to ae7dafd Compare March 3, 2021 22:56
@xlgmokha
Copy link
Contributor Author

xlgmokha commented Mar 3, 2021

Do you mind taking another look @feelepxyz?

@xlgmokha xlgmokha requested a review from feelepxyz March 3, 2021 23:38
Copy link
Contributor

@feelepxyz feelepxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one 🙌 LGTM

This was referenced Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants