Unverified Commit dd8323dc authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

fix(turbopack-swc-utils): Don't panic if issues aren't emitted, use…

fix(turbopack-swc-utils): Don't panic if issues aren't emitted, use `#[must_use]` annotation (#74906)

This is creating a ton of logspam for me when running tests. I can get dozens of these panics in a row.

It appears that there are functions that can return an `anyhow::Error` between collecting issues and emitting them. In those cases, it's not practical to ensure the issues are always emitted.

Instead, just settle for a much weaker compile-time check with `#[must_use]` that at least ensures something happens with `IssueCollector`.
parent 2f4610e3
...@@ -14,6 +14,7 @@ use turbopack_core::{ ...@@ -14,6 +14,7 @@ use turbopack_core::{
source::Source, source::Source,
}; };
#[must_use]
pub struct IssueCollector { pub struct IssueCollector {
inner: Arc<Mutex<IssueCollectorInner>>, inner: Arc<Mutex<IssueCollectorInner>>,
} }
...@@ -22,10 +23,6 @@ impl IssueCollector { ...@@ -22,10 +23,6 @@ impl IssueCollector {
pub async fn emit(self) -> Result<()> { pub async fn emit(self) -> Result<()> {
let issues = { let issues = {
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
if inner.emitted {
return Ok(());
}
inner.emitted = true;
take(&mut inner.emitted_issues) take(&mut inner.emitted_issues)
}; };
...@@ -43,18 +40,6 @@ impl IssueCollector { ...@@ -43,18 +40,6 @@ impl IssueCollector {
struct IssueCollectorInner { struct IssueCollectorInner {
emitted_issues: Vec<Vc<AnalyzeIssue>>, emitted_issues: Vec<Vc<AnalyzeIssue>>,
emitted: bool,
}
impl Drop for IssueCollectorInner {
fn drop(&mut self) {
if !self.emitted {
panic!(
"IssueCollector and IssueEmitter were dropped without calling \
`collector.emit().await?`"
);
}
}
} }
pub struct IssueEmitter { pub struct IssueEmitter {
...@@ -72,7 +57,6 @@ impl IssueEmitter { ...@@ -72,7 +57,6 @@ impl IssueEmitter {
) -> (Self, IssueCollector) { ) -> (Self, IssueCollector) {
let inner = Arc::new(Mutex::new(IssueCollectorInner { let inner = Arc::new(Mutex::new(IssueCollectorInner {
emitted_issues: vec![], emitted_issues: vec![],
emitted: false,
})); }));
( (
Self { Self {
...@@ -144,7 +128,6 @@ impl Emitter for IssueEmitter { ...@@ -144,7 +128,6 @@ impl Emitter for IssueEmitter {
); );
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
inner.emitted = false;
inner.emitted_issues.push(issue); inner.emitted_issues.push(issue);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment