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

--offline error with sparse index does not contain resolve hint #11276

Closed
ehuss opened this issue Oct 23, 2022 · 2 comments · Fixed by #11783
Closed

--offline error with sparse index does not contain resolve hint #11276

ehuss opened this issue Oct 23, 2022 · 2 comments · Fixed by #11783
Labels
A-offline Area: offline mode A-sparse-registry Area: http sparse registries C-bug Category: bug

Comments

@ehuss
Copy link
Contributor

ehuss commented Oct 23, 2022

Problem

When using --offline with sparse index, and attempting to resolve something that hasn't been fetched results in the following error:

error: failed to get `regex` as a dependency of package `foo v0.1.0 (/Users/eric/Temp/foo)`

Caused by:
  failed to query replaced source registry `crates-io`

Caused by:
  attempting to make an HTTP request, but --offline was specified

However, with non-sparse it gives the following if the index is out-of-date:

error: no matching package named `regex` found
location searched: registry `crates-io`
required by package `foo v0.1.0 (/Users/eric/Temp/foo)`
As a reminder, you're using offline mode (--offline) which can sometimes cause surprising resolution failures, if this error is too confusing you may wish to retry without the offline flag.

I think it would be good to consider the error message in this scenario to try to help explain why --offline may fail.

Steps

  1. cargo new foo
  2. cd foo
  3. echo 'regex = "*"' >> Cargo.toml
  4. cargo generate-lockfile -Zsparse-registry --offline

Possible Solution(s)

I suspect this may be very tricky, because I think the sparse code path is failing while updating the config.json file, long before resolution starts.

Notes

No response

Version

cargo 1.66.0-nightly (3ff044334 2022-10-17)
release: 1.66.0-nightly
commit-hash: 3ff044334f0567ce1481c78603aeee7211b91623
commit-date: 2022-10-17
host: x86_64-apple-darwin
libgit2: 1.5.0 (sys:0.15.0 vendored)
libcurl: 7.79.1 (sys:0.4.55+curl-7.83.1 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 12.6.0 [64-bit]
@ehuss ehuss added C-bug Category: bug A-sparse-registry Area: http sparse registries A-offline Area: offline mode labels Oct 23, 2022
@arlosi
Copy link
Contributor

arlosi commented Oct 24, 2022

If you've never fetched the sparse index, then the error message seems reasonable; and it does include the hint that the problem is caused by --offline. If the attempting to make an HTTP request, but --offline was specified error message isn't clear enough, we should change it.

However, we can probably do better when there is a local cache available, but the specific package requested isn't found. We can cause attempts to fetch a package in while in offline mode to return NotFound, which should match the git registry behavior.

@arlosi
Copy link
Contributor

arlosi commented Oct 24, 2022

We can also easily make a new error message for this specific scenario if that seems warranted.

no local cache of {registry_name} index is available, and offline mode (--offline) is specified

bors added a commit that referenced this issue Mar 1, 2023
Improve error for missing crate in --offline mode for sparse index

This changes sparse registries to instead return `NotFound` when a non-cached crate is requested in `--offline` mode.

The resolver can then suggest removing the `--offline` flag if resolution fails, which is a more helpful error than the one currently issued: `attempting to make an HTTP request, but --offline was specified`.

With this change, the behavior matches what is already done for git-based registries.

Closes #11276
@bors bors closed this as completed in dbb2d67 Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-offline Area: offline mode A-sparse-registry Area: http sparse registries C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants