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

No regex capture while parsing search output for ... #6

Closed
jwest23 opened this issue Oct 25, 2023 · 8 comments
Closed

No regex capture while parsing search output for ... #6

jwest23 opened this issue Oct 25, 2023 · 8 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers
Milestone

Comments

@jwest23
Copy link

jwest23 commented Oct 25, 2023

Description
Running cargo liner when the liner.toml contains references to certain packages causes it to error out:

❯ cargo liner
 INFO  cargo_liner::cargo > Fetching latest package versions...
 ERROR cargo_liner        > No regex capture while parsing search output for "cargo-nextest".
❯ cargo liner
 INFO  cargo_liner::cargo > Fetching latest package versions...
 ERROR cargo_liner        > No regex capture while parsing search output for "tokei".

The package versions are currently:

cargo-nextest: 0.9.62-a.2
tokei: 13.0.0-alpha.0

Expected behavior
Installation of cargo-nextest and tokei.

To Reproduce

  1. Create a liner.toml with the content:
[packages]
cargo-nextest = "*"
tokei = "*"
  1. Run cargo liner
  2. See the resulting error.

Output

❯ cat liner.toml
[packages]
tokei = "*"

❯ cargo liner --verbose
 DEBUG cargo_liner::config::user_config > Building file path...
 DEBUG cargo_liner::config::user_config > Reading configuration from "/home/jwest/.cargo/liner.toml"...
 DEBUG cargo_liner::config::user_config > Deserializing contents...
 DEBUG cargo_liner::config::user_config > Self-updating enabled.
 DEBUG cargo_liner::config::cargo_crates_toml > Building file path...
 DEBUG cargo_liner::cargo                     > Running "/home/jwest/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo" with arguments [
    "-Z",
    "unstable-options",
    "config",
    "get",
    "--format",
    "json-value",
    "install.root",
]...
 DEBUG cargo_liner::config::cargo_crates_toml > Failed to retrieve `install.root` from Cargo's configuration on error: "Command failed with status: ExitStatus(\n    unix_wait_status(\n        25856,\n    ),\n) and stderr: \"error: config value `install.root` is not set\\n\".".
 DEBUG cargo_liner::config::cargo_crates_toml > Defaulting to Cargo's home directory...
 DEBUG cargo_liner::config::cargo_crates_toml > Reading Cargo-installed packages from "/home/jwest/.cargo/.crates.toml"...
 DEBUG cargo_liner::config::cargo_crates_toml > Deserializing packages...
 INFO  cargo_liner::cargo                     > Fetching latest package versions...
 DEBUG cargo_liner::cargo                     > Spawning search child processes in parallel...
 DEBUG cargo_liner::cargo                     > Running "/home/jwest/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo" with arguments [
    "search",
    "--limit=1",
    "cargo-liner",
]...
 DEBUG cargo_liner::cargo                     > Running "/home/jwest/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo" with arguments [
    "search",
    "--limit=1",
    "tokei",
]...
 DEBUG cargo_liner::cargo                     > Waiting for each search child processes to finish...
 ERROR cargo_liner                            > No regex capture while parsing search output for "tokei".

❯ cargo liner --version
cargo-liner 0.4.1

Context

  • OS: Debian Linux
  • OS version: Debian 11.8
  • Rust version: 1.73.0
  • Project version: 0.4.1

Additional information
Thanks for cargo-liner and for looking into this!

@jwest23 jwest23 added the bug Something isn't working label Oct 25, 2023
@PaulDance
Copy link
Owner

Hi @jwest23,

Thanks for the detailed report!

I can indeed easily reproduce the issue. Using -vvv, we can see that:

TRACE cargo_liner::cargo > Search for "tokei" got: "tokei = \"13.0.0-alpha.0\"    # Count your code, quickly.\n... and 38 crates more (use --limit N to see more)\n"

The search in itself therefore succeeds, but the version extraction then fails. Looking at the cargo::finish_search_exact function, we can see that [0-9.abrc]+ is used as the regular expression capture group in order to match and extract the version string: it is too conservative and does not match any - or alpha.

This should therefore be easy to fix: extending the capture group to be something in the likes of [0-9a-zA-Z.+-]+ should do the trick. Indeed:

  • Cargo and crates.io use SemVer, or some close variant of it.
  • The SemVer specification shows only these characters are used.
  • semver::Version::parse will still do the proper strict parsing on top of the lax extraction.

I'll try this some time soon, most probably tomorrow night at the latest.

Thanks for cargo-liner and for looking into this!

❤️

@PaulDance PaulDance self-assigned this Oct 26, 2023
@jwest23
Copy link
Author

jwest23 commented Oct 27, 2023

My "Expected Behavior" could use a little polish.

Expected Behavior
Installation of cargo-nextest 0.9.59 and tokei 12.1.2, with an alert that these newer versions are also available.

When encountering a version with a pre-alpha or build metadata extension such as cargo-nextest 0.9.62-a.2 or tokei 13.0.0-alpha.0 cargo-liner would:

  1. alert me that these versions are available
  2. walk backwards through the versions until it finds a version without an extension and if it finds one, consider that the latest version instead
  3. never automatically upgrade to a version with a pre-alpha or build metadata extension; maybe allow it with a command-line switch or other configuration

This is similar to the behavior of cargo-update; cargo install-update --list shows both of these as:

Package                 Installed  Latest                                                    Needs update
cargo-nextest       v0.9.61     v0.9.61 (v0.9.62-a.2 available)          No
tokei                       v12.1.2     v12.1.2 (v13.0.0-alpha.0 available)  No

which is helpful when deciding how I want to proceed.

Thank you again! cargo-liner has greatly improved the consistency of which tools are available to me in my various environments and saves me a ton of time!

@PaulDance
Copy link
Owner

Yes, I see what you mean. Thanks for clarifying.

However, you should know that the versions passed onto calls to cargo install are exactly the values of the packages config section without any kind of transformation whatsoever and it handles it just fine: that was by design. You can see that if you run:

❯ cargo install --version '*' cargo-nextest
    Updating crates.io index
  Installing cargo-nextest v0.9.61

What you want should therefore already be done: only the stable version is used. The versions that you see on the standard output are only coming from the result of calls to cargo search and is only used for display and in order to detect whether a new version is available or not.

It therefore seems to me the two issues are separate: could you move that into another issue then? Also please keep bugs and feature requests separate as well, it helps my understanding of things.

@PaulDance
Copy link
Owner

@jwest23 The issue I just opened should cover what I found concerning this from the point of bugs. Feel free to open another bug or feature request issue if it does not cover exactly what you had in mind, however.

PaulDance added a commit that referenced this issue Oct 27, 2023
…utput extraction

`semver::Version` still applies a stricter parsing after.

Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>
@PaulDance
Copy link
Owner

The commit I just pushed should fix the direct issue:

  • cargo-nextest v0.9.61
  • tokei v12.1.2

were installed instead of the pre-release versions available. You should thus be able to use that commit by installing from source with cargo install --git [...] while waiting for a proper release.

I am therefore going to close this, but if it actually does not work for you, feel free to re-open it.

@Johnabell
Copy link
Contributor

Would it be possible to make this fix available in a release version now? We also ran into this issue in our CI pipeline.

@PaulDance
Copy link
Owner

Yes, with your recent #9 and #8 being postponed, I'm planning on doing that in the coming days, especially if you're expecting it.

@PaulDance
Copy link
Owner

Fix released as part of v0.4.2.

PaulDance added a commit that referenced this issue Feb 3, 2024
Signed-off-by: Paul Mabileau <paulmabileau@hotmail.fr>
@PaulDance PaulDance added the good first issue Good for newcomers label Feb 13, 2024
@PaulDance PaulDance added this to the v0.4.2 milestone Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants