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

Improve error messages for incompatible direct requirements #338

Closed
wants to merge 2 commits into from

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Nov 6, 2023

Addresses #309 (comment)

Instead of running the resolver with a requirement with an empty range of versions, we error early with a message indicating the conflict that resulted in an empty set.

Example at https://github.com/astral-sh/puffin/pull/338/files#diff-d09432742ed63e9e76729f7fdb52772366e983f14e9551bc6f64e4329bdd20e7

Comment on lines +120 to 124

pub fn is_empty(&self) -> bool {
return self.segments.is_empty();
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Needed a way to check for emptiness...

Copy link
Member Author

Choose a reason for hiding this comment

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

Note this tweaks the vendored pubgrub

Comment on lines 42 to 43
#[error("Conflicting versions for package `{0}`: {1} is incompatible with {2}")]
ConflictingPackageVersions(PackageName, Range<PubGrubVersion>, Range<PubGrubVersion>),
Copy link
Member Author

Choose a reason for hiding this comment

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

Clippy is upset by the size of this variant. Suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

For e.g. error structs i ignore them

Copy link
Member Author

Choose a reason for hiding this comment

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

I think then we also have to ignore in all the methods with #[allow(clippy::result_large_err)]? Seems annoying

Copy link
Member

Choose a reason for hiding this comment

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

ugh that is significantly more annoying :/ in that case you might really want to box

@zanieb
Copy link
Member Author

zanieb commented Nov 6, 2023

There are some limitations here, like we will display the merged version on one side if there has been more than one previous version specifiers.

@zanieb zanieb changed the title Improve error messages for incompatible, direct requirements Improve error messages for incompatible direct requirements Nov 6, 2023
))
} else {
Ok(version)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think there's a problem with this approach which I also ran into with the "error if a package is requested under two different URLs" thing, which is that it doesn't let us backtrack out of the error state. So if the resolver ever sees a package with a version that has these conflicting requirements internally, it will immediately fail, rather than rejecting that version and attempting to backtrack to a working state.

Is that clear? I don't know how to solve this.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense. Do we do try_from_requirements on requirements of dependencies i.e. indirect dependencies?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah we do.

Copy link
Member

Choose a reason for hiding this comment

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

(I tend to call those "transitive dependencies".)

Copy link
Member

Choose a reason for hiding this comment

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

I guess the other issue here is that we won't print out a "tree" of incompatibilities, we'll just tell you which package failed, but not why that package was required. I'm wondering if we can add a new incompatibility kind to support this instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes that's a good word for them. Okay... let me look for a better way to handle this then.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it seems like it should be an incompatibility, I did not realize this was used for transitive dependencies.

zanieb added a commit that referenced this pull request Nov 16, 2023
…cting versions (#424)

Addresses
#309 (comment)

Similar to #338 this throws an error when merging versions results in an
empty set. Instead of propagating that error, we capture it and return a
new dependency type of `Unusable`. Unusable dependencies are a new
incompatibility kind which includes an arbitrary "reason" string that we
present to the user. Adding a new incompatibility kind requires changes
to the vendored pubgrub crate.

We could use this same incompatibility kind for conflicting urls as in
#284 which should allow the solver to backtrack to another valid version
instead of failing (see #425).

Unlike #383 this does not require changes to PubGrub's package mapping
model. I think in the long run we'll want PubGrub to accept multiple
versions per package to solve this specific issue, but we're interested
in it being merged upstream first. This pull request is just using the
issue as a simple case to explore adding a new incompatibility type.

We may or may not be able convince them to add this new incompatibility
type upstream. As discussed in
pubgrub-rs/pubgrub#152, we may want a more
general incompatibility kind instead which can be used for arbitrary
problems. An upstream pull request has been opened for discussion at
pubgrub-rs/pubgrub#153.

Related to:
- pubgrub-rs/pubgrub#152
- #338 
- #383

---------

Co-authored-by: konsti <konstin@mailbox.org>
@zanieb zanieb closed this Nov 20, 2023
@zanieb
Copy link
Member Author

zanieb commented Nov 20, 2023

Using #424 instead

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.

None yet

3 participants