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

Panic when running cargo update in a [workspace] only crate with 2 package crate in it's dir #3080

Closed
codyps opened this issue Sep 10, 2016 · 11 comments
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. E-easy Experience: Easy

Comments

@codyps
Copy link
Contributor

codyps commented Sep 10, 2016

src: https://github.com/jmesmon/ioctl/tree/workspace-cargo-bug

x@y /home/x/g/ioctl % cargo -V
cargo 0.13.0-nightly (afaffa1 2016-09-06)
x@y /home/x/g/ioctl % RUST_BACKTRACE=1 cargo update
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', ../src/libcore/option.rs:317
stack backtrace:
   1:     0x5588935680a3 - std::sys::backtrace::tracing::imp::write::h46f28e67d38b4637
   2:     0x55889357150d - std::panicking::default_hook::{{closure}}::h1d3243f546573ff4
   3:     0x55889357079a - std::panicking::default_hook::h96c288d728df3ebf
   4:     0x558893570d98 - std::panicking::rust_panic_with_hook::hb1322e5f2588b4db
   5:     0x558893570c32 - std::panicking::begin_panic::hfbeda5aad583dc32
   6:     0x558893570b70 - std::panicking::begin_panic_fmt::h4fe9fb9d5109c4bf
   7:     0x558893570af1 - rust_begin_unwind
   8:     0x5588935adc9f - core::panicking::panic_fmt::h4395919ece15c671
   9:     0x5588935adbcb - core::panicking::panic::hc74ff52ed78364e1
  10:     0x5588931b36d3 - cargo::ops::lockfile::write_pkg_lockfile::h162deef0c25d5dc1
  11:     0x558893141d59 - cargo::ops::cargo_generate_lockfile::generate_lockfile::h1961a4fa38b887c3
  12:     0x558893141fc7 - cargo::ops::cargo_generate_lockfile::update_lockfile::h35287c4bedfd66e4
  13:     0x558893075687 - cargo::try_execute::hac87fe5021ec29cd
  14:     0x55889304c135 - cargo::execute::hf5ba8f03b1a33e9a
  15:     0x55889303e164 - cargo::call_main_without_stdin::h12b4266586e2d4eb
  16:     0x55889304a9c4 - cargo::main::ha1e5f2a52416e0a7
  17:     0x558893578fd6 - __rust_maybe_catch_panic
  18:     0x558893570011 - std::rt::lang_start::haaae1186de9de8cb
  19:     0x7f937807f290 - __libc_start_main
  20:     0x558893031328 - <unknown>
x@y /home/x/g/ioctl % git status --ignored
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)
Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

        Cargo.toml~
        base/Cargo.toml~
        base/examples/smoke.rs~
        base/src/lib.rs~
        base/src/platform/linux.rs~
        sys/Cargo.toml~
        sys/etc/process_ioctls.py~
        sys/src/lib.rs~
        sys/src/platform/linux.rs~

nothing to commit, working tree clean
@codyps
Copy link
Contributor Author

codyps commented Sep 10, 2016

Minimal reproduction:

mkdir ws
cd ws
echo '[workspace]' >Cargo.toml
cargo new p1
cargo new p2
cargo update

Probably should complain about current package believes it's in a workspace when it's not again.

@alexcrichton
Copy link
Member

I believe that the unwrap is this line, and yeah I think Cargo just needs to yield an error here instead saying you can't generate a lock file for an empty workspace.

@alexcrichton alexcrichton added the A-diagnostics Area: Error and warning messages generated by Cargo itself. label Sep 12, 2016
@alexcrichton
Copy link
Member

Should be an easy bug to tackle though!

@alexcrichton alexcrichton added the E-easy Experience: Easy label Sep 12, 2016
@jhbabon
Copy link
Contributor

jhbabon commented Sep 13, 2016

@alexcrichton I can have a look at this if nobody else is doing it.

@alexcrichton
Copy link
Member

@jhbabon all yours! Let me know if you need any pointers.

@jhbabon
Copy link
Contributor

jhbabon commented Sep 13, 2016

@alexcrichton I was thinking, maybe it is not better to put this in the validate() method of the Workspace struct?

fn validate(&mut self) -> CargoResult<()> {

@alexcrichton
Copy link
Member

Hm yeah, that actually sounds like a much better place to put it!

@jhbabon
Copy link
Contributor

jhbabon commented Sep 14, 2016

@alexcrichton so I've been investigating a bit more, and I think this error happens with commands like update because these commands never use the method Workspace.current(). This method only works if the current package is not virtual and I think that's our case. We don't want the command update to run on virtual workspaces, just actual packages, right? Or I'm missing something?

If this is the case, maybe we can validate that the workspace it's not virtual during the execution of the update command. This way the command will be consistent with others like build that displays an error like this:

manifest path `[..]` is a virtual manifest, but this command requires running against an actual package in this workspace

@jhbabon
Copy link
Contributor

jhbabon commented Sep 14, 2016

I came up with this solution, but I don't know if it's the best option: #3092

bors added a commit that referenced this issue Sep 14, 2016
…chton

FIX: Don't try to generate Gargo.lock on empty workspaces.

There was a `panic!` when the command `cargo update` was executed in a workspace like this:

    mkdir ws
    cd ws
    echo '[workspace]' > Cargo.toml
    cargo new p1
    cargo new p2
    cargo update

The problem is that cargo tries to generate the `Cargo.lock` file even if there aren't any members on the workspace.

This fix checks the existence of members in the workspace before trying to do anything so at least we report an error instead of throwing a `panic!`.

Issue related #3080
@jhbabon
Copy link
Contributor

jhbabon commented Sep 15, 2016

Should we consider to close this after this merge #3092 ?

@alexcrichton
Copy link
Member

Indeed, thanks @jhbabon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. E-easy Experience: Easy
Projects
None yet
Development

No branches or pull requests

3 participants