Skip to content

Commit d2a66d6

Browse files
authored
feat: Don't stop at first error when emitting lints and warnings (#15889)
While emitting warnings, if `cargo` encounters a critical warning or an error while linting, it returns early, potentially before all packages could emit their warnings or be linted. This could make it so users have to run a `cargo` command more than once before seeing all of the relevant output. Beyond this, having an error caused by a lint be a "stop the world" event seems wrong, as it (currently) doesn't inhibit outputting other warnings or linting other packages. To address this, I made it so that `cargo` waits until the end of `emit_warnings` to return an error if one was encountered. To keep the cause of the error the same as before, `cargo` saves off the first error it encounters, and returns it at the end.
2 parents 51d077c + 19fb2c0 commit d2a66d6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/cargo/core/workspace.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,10 +1205,15 @@ impl<'gctx> Workspace<'gctx> {
12051205
}
12061206

12071207
pub fn emit_warnings(&self) -> CargoResult<()> {
1208+
let mut first_emitted_error = None;
12081209
for (path, maybe_pkg) in &self.packages.packages {
12091210
if let MaybePackage::Package(pkg) = maybe_pkg {
12101211
if self.gctx.cli_unstable().cargo_lints {
1211-
self.emit_lints(pkg, &path)?
1212+
if let Err(e) = self.emit_lints(pkg, &path)
1213+
&& first_emitted_error.is_none()
1214+
{
1215+
first_emitted_error = Some(e);
1216+
}
12121217
}
12131218
}
12141219
let warnings = match maybe_pkg {
@@ -1220,7 +1225,9 @@ impl<'gctx> Workspace<'gctx> {
12201225
let err = anyhow::format_err!("{}", warning.message);
12211226
let cx =
12221227
anyhow::format_err!("failed to parse manifest at `{}`", path.display());
1223-
return Err(err.context(cx));
1228+
if first_emitted_error.is_none() {
1229+
first_emitted_error = Some(err.context(cx));
1230+
}
12241231
} else {
12251232
let msg = if self.root_manifest.is_none() {
12261233
warning.message.to_string()
@@ -1233,7 +1240,12 @@ impl<'gctx> Workspace<'gctx> {
12331240
}
12341241
}
12351242
}
1236-
Ok(())
1243+
1244+
if let Some(error) = first_emitted_error {
1245+
Err(error)
1246+
} else {
1247+
Ok(())
1248+
}
12371249
}
12381250

12391251
pub fn emit_lints(&self, pkg: &Package, path: &Path) -> CargoResult<()> {

0 commit comments

Comments
 (0)