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

Checking crates without a lib target causes a crash #451

Closed
marcoieni opened this issue May 7, 2023 · 4 comments · Fixed by #477
Closed

Checking crates without a lib target causes a crash #451

marcoieni opened this issue May 7, 2023 · 4 comments · Fixed by #477
Labels
A-cli Area: engine around the lints C-bug Category: doesn't meet expectations E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: Mentorship is available for this issue.

Comments

@marcoieni
Copy link
Contributor

Steps to reproduce the bug with the above code

git clone https://github.com/MarcoIeni/release-plz
cargo-semver-checks semver-checks check-release -p release-plz

Actual Behaviour

$ cargo-semver-checks semver-checks check-release -p release-plz
    Updating index
     Parsing release-plz v0.3.7 (current)
Well, this is embarrassing.

cargo-semver-checks had a problem and crashed. To help us diagnose the problem you can send us a crash report.

We have generated a report file at "/var/folders/n1/c6p1r6x10vz3wx7qpzrs8l780000gn/T/report-80083e25-4762-4ac8-bbd4-c4ef7c3c7600.toml". Submit an issue or email with the subject of "cargo-semver-checks Crash Report" and include the report as an attachment.

- Authors: Predrag Gruevski <obi1kenobi82@gmail.com>

We take privacy seriously, and do not perform any automated error collection. In order to improve the software, we rely on people to submit reports.

Thank you kindly!

Expected Behaviour

The program shouldn't panic.

Generated System Information

Software version

cargo-semver-checks 0.20.0

Operating system

macOS 13.1 (Darwin 22.2.0)

Command-line

/Users/marcoieni/.cargo/bin/cargo-semver-checks semver-checks --bugreport

cargo version

> cargo -V
cargo 1.69.0 (6e9a83356 2023-04-12)

Compile time information

  • Profile: release
  • Target triple: aarch64-apple-darwin
  • Family: unix
  • OS: macos
  • Architecture: aarch64
  • Pointer width: 64
  • Endian: little
  • CPU features: aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh
  • Host: aarch64-apple-darwin

Build Configuration

$ env | grep CARGO
CARGO_TARGET_DIR=/Users/marcoieni/.cargo-target

Additional Context

$ cat /var/folders/n1/c6p1r6x10vz3wx7qpzrs8l780000gn/T/report-80083e25-4762-4ac8-bbd4-c4ef7c3c7600.toml
name = "cargo-semver-checks"
operating_system = "Mac OS 13.1.0 [64-bit]"
crate_version = "0.20.0"
explanation = """
Panic occurred in file '/Users/marcoieni/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-semver-checks-0.20.0/src/rustdoc_cmd.rs' at line 136
"""
cause = "we declared a dependency on a crate that doesn't exist in the metadata"
method = "Panic"
backtrace = """

   0: 0x1049a2ae8 - core::panicking::panic_fmt::h7e47e10600a90221
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64
   1: 0x104967e10 - core::panicking::panic_display::h940323af6be747f0
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:147
   2: 0x104967dd4 - core::panicking::panic_str::h7ca06b5260522b55
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:131
   3: 0x1049a2ab4 - core::option::expect_failed::h3fd9ac3cfb0d19fd
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/option.rs:2045
   4: 0x1041d219c - cargo_semver_checks::rustdoc_gen::generate_rustdoc::h35486f6a3d98e2f9
   5: 0x1041d3a18 - <cargo_semver_checks::rustdoc_gen::RustdocFromProjectRoot as cargo_semver_checks::rustdoc_gen::RustdocGenerator>::load_rustdoc::h998791847635f4db
   6: 0x10427b21c - cargo_semver_checks::generate_versioned_crates::haef37b1306b47b86
   7: 0x1041c0260 - <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold::h2123bc4cb574cc53
   8: 0x104294578 - <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter::hef289b4d05b10858
   9: 0x10427ad40 - cargo_semver_checks::Check::check_release::h601b6e3d52735cf2
  10: 0x1040de6e8 - cargo_semver_checks::main::h6951fd5f96fab30a
  11: 0x1040d9898 - std::sys_common::backtrace::__rust_begin_short_backtrace::h95ba3cfefa555d53
  12: 0x1040d3150 - std::rt::lang_start::{{closure}}::h665df64f8cf70e09
  13: 0x104943e74 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hf2f6b444963da11f
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/ops/function.rs:287
                 - std::panicking::try::do_call::h9152231fddd58858
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:487
                 - std::panicking::try::hcc27eab3b8ee3cb1
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:451
                 - std::panic::catch_unwind::hca546a4311ab9871
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panic.rs:140
                 - std::rt::lang_start_internal::{{closure}}::h4e65aa71fe685c85
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/rt.rs:148
                 - std::panicking::try::do_call::h61aea55fbdf97fc2
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:487
                 - std::panicking::try::hcfc3b62fb8f6215e
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:451
                 - std::panic::catch_unwind::h61a201e98b56a743
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panic.rs:140
                 - std::rt::lang_start_internal::h91996717d3eb1d2a
                at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/rt.rs:148
  14: 0x1040e2ce0 - _main"""
@marcoieni marcoieni added the C-bug Category: doesn't meet expectations label May 7, 2023
@marcoieni
Copy link
Contributor Author

I was trying to understand if it's possible to run the cargo-semver-checks binary in parallel in the same workspace for different crates.
While doing it, I got this error. Now I can reproduce it also after running cargo clean and running 1 instance of cargo-semver-checks.
Can you also reproduce it?

@obi1kenobi obi1kenobi added A-cli Area: engine around the lints E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: Mentorship is available for this issue. labels May 7, 2023
@obi1kenobi
Copy link
Owner

@thomaseizinger reported the same crash to me over email a few days ago, I just forgot to open an issue.

It happens because cargo-semver-checks tried to semver-check a crate with no lib target (e.g. a bin crate). release-plz seems to be a bin crate, not a library, so there's no library API to check.

The fix is to check whether crates have a lib target, both in current and in baseline:

  • If both current and baseline have lib targets, proceed as normal.
  • If current has a lib target but baseline does not, print a warning but exit 0. There can't be any breaking changes since previously there was no library to depend on.
  • If current doesn't have a lib target, then what we do depends on whether we're checking an entire workspace or not.

In a workspace, we skip crates with no lib targets just like we skip crates with publish = false. Ideally this would log an "INFO" level message when running verbosely so the user knows it's happening. Info not warning because we don't want to be annoying -- large projects like tokio would have many crates skipped like this.

Otherwise, if told to check a specific crate directly, we should exit with an error saying that the crate has no lib target to check. I believe this is the case your command hit here.

I have one heck of a busy week coming up so I don't think I'll be able to look at this particularly soon. Might you be interested @marcoieni? I'd be happy to code review and point you in the right direction, of course.

@marcoieni
Copy link
Contributor Author

Thanks for the explanation! Unfortunately I have no time to work on this :(

@obi1kenobi
Copy link
Owner

I am only too familiar with the feeling! 😅

@obi1kenobi obi1kenobi changed the title Crash: we declared a dependency on a crate that doesn't exist in the metadata Checking crates without a lib target causes a crash May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: engine around the lints C-bug Category: doesn't meet expectations E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: Mentorship is available for this issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants