Skip to content

Detect missing default members without catching a panic - #658

Open
Cayan wants to merge 1 commit into
sourcefrog:mainfrom
Cayan:use-workspace-default-members-api
Open

Cayan wants to merge 1 commit into
sourcefrog:mainfrom
Cayan:use-workspace-default-members-api

Conversation

@Cayan

@Cayan Cayan commented Sep 29, 2026

Copy link
Copy Markdown

Fixes #474.

default_packages wrapped workspace_default_packages() in catch_unwind because it panics when Cargo older than 1.71 doesn't report default members. cargo_metadata 0.23 has WorkspaceDefaultMembers::is_available(), so this checks it first and falls back to testing all packages, as before, without the panic.

Added unit tests for both paths, using the workspace_default_members fixture: one expects the declared default member, the other clears the default members to simulate older Cargo and expects all packages. The fallback test fails with the cargo_metadata panic if the check is removed.

cargo test --bin cargo-mutants workspace::, cargo fmt --all --check and cargo clippy --all-targets pass.

- Check `WorkspaceDefaultMembers::is_available()` before reading the default members, instead of
  catching the panic `workspace_default_packages()` raises when Cargo older than 1.71 omits them.
- The fallback to testing all packages is unchanged, and unit tests now cover both paths.
@sourcefrog

Copy link
Copy Markdown
Owner

Thanks. Out of interest, did you actually hit a bug related to this? Or you just wanted to fix an open bug?

@Cayan

Cayan commented Oct 1, 2026

Copy link
Copy Markdown
Author

No, I didn't hit it. I picked #474 from the open issues to get to know the codebase.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use new cargo-metadata API to check if workspace default members can be read

2 participants