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

Include location of workspace manifest in error loading workspace #13394

Closed
fawq opened this issue Feb 4, 2024 · 10 comments · Fixed by #13480
Closed

Include location of workspace manifest in error loading workspace #13394

fawq opened this issue Feb 4, 2024 · 10 comments · Fixed by #13480
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@fawq
Copy link

fawq commented Feb 4, 2024

Problem

I've tried to create new project inside project which was previously created by cargo init and removed. Now when I want to create new project inside, I've got an error that there is a missing Cargo.toml in parent directory, but parent directory doesn't need to have Cargo.toml because it should be simple directory contains all rust projects.

Steps:

  1. Create directory e.g. "/home/ubuntu/Projects/Rust/"
  2. Go inside this directory and type cargo init
  3. Change mind and remove all files rm -r *
  4. Create new project inside this directory e.g. cargo new test_rust_wsl
  5. New directory is created "/home/ubuntu/Projects/Rust/test_rust_wsl"
  6. Go inside new directory and try build cargo build

Get the error:

error: failed to load manifest for workspace member /home/ubuntu/Projects/Rust

Caused by:
failed to read /home/ubuntu/Projects/Rust/Cargo.toml

Caused by:
No such file or directory (os error 2)

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.75.0 (1d8b05cdd 2023-11-20)
release: 1.75.0
commit-hash: 1d8b05cdd1287c64467306cf3ca2c8ac60c11eb0
commit-date: 2023-11-20
host: x86_64-unknown-linux-gnu
libgit2: 1.7.1 (sys:0.18.1 vendored)
libcurl: 8.4.0-DEV (sys:0.4.68+curl-8.4.0 vendored ssl:OpenSSL/1.1.1u)
ssl: OpenSSL 1.1.1u  30 May 2023
os: Ubuntu 22.04 (jammy) [64-bit]
@fawq fawq added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Feb 4, 2024
@fawq fawq changed the title Cargo serach for non-existing Cargo.toml Cargo search for non-existing Cargo.toml Feb 4, 2024
@ehuss
Copy link
Contributor

ehuss commented Feb 4, 2024

Hm, it seems like there is a possible step missing from the reproduction. Can you check if you have a Cargo.toml located in any parent directory of /home/ubuntu/Projects/Rust? Or perhaps there is a workspace table in /home/ubuntu/Projects/Rust/test_rust_wsl/Cargo.toml?

@fawq
Copy link
Author

fawq commented Feb 4, 2024

image
image
As you can see, there is no other Cargo.toml in a whole directory (except the one which I need and cannot build)

@ehuss
Copy link
Contributor

ehuss commented Feb 4, 2024

Can you check the parents of the Projects directory, such as /home/ubuntu, /home, or /? Cargo searches all ancestor directories for a Cargo.toml.

Probably the easiest thing to do is to copy the output of CARGO_LOG=trace cargo build

@fawq
Copy link
Author

fawq commented Feb 4, 2024

Thanks for help, it was created in home directory. The question is why it was not detected or printed by inside project? Is it possible to get from cargo build more information about "parent workspace"? Or only CARGO_LOG=trace cargo build can found the issue? Nevertheless, Issue can be closed, I think.

@ehuss
Copy link
Contributor

ehuss commented Feb 4, 2024

For now, CARGO_LOG seems to be the only way to debug this particular issue.

I think it would be good to keep this open as a suggestion to improve the error message so that it tells you where the workspace manifest is located.

@ehuss ehuss added A-diagnostics Area: Error and warning messages generated by Cargo itself. S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-triage Status: This issue is waiting on initial triage. labels Feb 4, 2024
@ehuss ehuss changed the title Cargo search for non-existing Cargo.toml Include location of workspace manifest in error loading workspace Feb 4, 2024
@weihanglo
Copy link
Member

weihanglo commented Feb 4, 2024

I wonder if this happened because cargo new adds the new package to the workspace found without any notice (since #12779).

#13391 may make this kind of issues less frequent. cargo new might also print a note when workspace inheritance happens.

@tusharxoxoxo
Copy link

tusharxoxoxo commented Feb 20, 2024

I am unable to reproduce this issue locally on my machine.
This issue shouldn't have occurred as cargo reads all the cargo.toml files from all the above folders in the hierarchy and create the build and if there was some cargo.toml in the hierarchy then i should be able to create the build

Can someone tell me if I correctly understood this issue and how I could reproduce this issue on my machine locally?

image

@tusharxoxoxo
Copy link

is this the cause of this issue??
At some point, you might have accidentally initialized a Rust project (with cargo new) from the /home directory, making that entire directory the project root.

@tusharxoxoxo
Copy link

I think i kind of able to reproduce it, but i am getting slightly different errors compared to what is mentioned above, i created a copy of my cargo.toml in my home directory for this

image

@ehuss
Copy link
Contributor

ehuss commented Feb 20, 2024

@tusharxoxoxo To reproduce:

Create a Cargo.toml with the contents:

[workspace]
members = ["foo", "bar"]

Then:

  • cargo new --lib bar
  • cd bar
  • cargo build

The last step should show:

error: failed to load manifest for workspace member `/path/to/foo`

Notice that the error does not display the path to the workspace Cargo.toml (which is where the problem is, because the members field points to a directory "foo" that does not exist).

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. C-bug Category: bug S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
4 participants