Skip to content

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

@ehuss

Description

@ehuss

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions