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

Turbopack: Improve the description on InvalidLoaderRuleConditionIssue (#87008)

It's near-impossible to get this to error on the Rust side (issues are caught before we get here), but I hacked up the code to make it error. It looks like this:

![Screenshot 2025-12-09 at 4.39.24 PM.png](https://app.graphite.com/user-attachments/assets/796b5efa-b2e5-4a9c-bcf3-03cee0a0861d.png)
parent 940f8892
...@@ -1283,6 +1283,7 @@ impl Issue for InvalidLoaderRuleRenameAsIssue { ...@@ -1283,6 +1283,7 @@ impl Issue for InvalidLoaderRuleRenameAsIssue {
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
struct InvalidLoaderRuleConditionIssue { struct InvalidLoaderRuleConditionIssue {
error_string: RcStr,
condition: ConfigConditionItem, condition: ConfigConditionItem,
config_file_path: FileSystemPath, config_file_path: FileSystemPath,
} }
...@@ -1307,7 +1308,15 @@ impl Issue for InvalidLoaderRuleConditionIssue { ...@@ -1307,7 +1308,15 @@ impl Issue for InvalidLoaderRuleConditionIssue {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn description(&self) -> Result<Vc<OptionStyledString>> { async fn description(&self) -> Result<Vc<OptionStyledString>> {
Ok(Vc::cell(Some( Ok(Vc::cell(Some(
StyledString::Text(RcStr::from(format!("{:#?}", self.condition))).resolved_cell(), StyledString::Stack(vec![
StyledString::Line(vec![
StyledString::Text(rcstr!("Encountered the following error: ")),
StyledString::Code(self.error_string.clone()),
]),
StyledString::Text(rcstr!("While processing the condition:")),
StyledString::Code(RcStr::from(format!("{:#?}", self.condition))),
])
.resolved_cell(),
))) )))
} }
...@@ -1497,10 +1506,11 @@ impl NextConfig { ...@@ -1497,10 +1506,11 @@ impl NextConfig {
// convert from Next.js-specific condition type to internal Turbopack // convert from Next.js-specific condition type to internal Turbopack
// condition type // condition type
let condition = if let Some(condition) = condition { let condition = if let Some(condition) = condition {
if let Ok(cond) = ConditionItem::try_from(condition.clone()) { match ConditionItem::try_from(condition.clone()) {
Some(cond) Ok(cond) => Some(cond),
} else { Err(err) => {
InvalidLoaderRuleConditionIssue { InvalidLoaderRuleConditionIssue {
error_string: RcStr::from(err.to_string()),
condition: condition.clone(), condition: condition.clone(),
config_file_path: self config_file_path: self
.config_file_path(project_path.clone()) .config_file_path(project_path.clone())
...@@ -1511,6 +1521,7 @@ impl NextConfig { ...@@ -1511,6 +1521,7 @@ impl NextConfig {
.emit(); .emit();
None None
} }
}
} else { } else {
None None
}; };
......
module.exports = {
turbopack: {
rules: {
"*.svg": {
loaders: ["@svgr/webpack"],
as: "*.js",
condition: {
path: /abc/,
},
},
},
},
};
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