Repository: vercel/next.js
Pull request: Turbopack: Improve the description on InvalidLoaderRuleConditionIssue

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)

Changed files:
filename: crates/next-core/src/next_config.rs
patch: @@ -1283,6 +1283,7 @@ impl Issue for InvalidLoaderRuleRenameAsIssue {
 
 #[turbo_tasks::value(shared)]
 struct InvalidLoaderRuleConditionIssue {
+    error_string: RcStr,
     condition: ConfigConditionItem,
     config_file_path: FileSystemPath,
 }
@@ -1307,7 +1308,15 @@ impl Issue for InvalidLoaderRuleConditionIssue {
     #[turbo_tasks::function]
     async fn description(&self) -> Result<Vc<OptionStyledString>> {
         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,19 +1506,21 @@ impl NextConfig {
                         // convert from Next.js-specific condition type to internal Turbopack
                         // condition type
                         let condition = if let Some(condition) = condition {
-                            if let Ok(cond) = ConditionItem::try_from(condition.clone()) {
-                                Some(cond)
-                            } else {
-                                InvalidLoaderRuleConditionIssue {
-                                    condition: condition.clone(),
-                                    config_file_path: self
-                                        .config_file_path(project_path.clone())
-                                        .owned()
-                                        .await?,
+                            match ConditionItem::try_from(condition.clone()) {
+                                Ok(cond) => Some(cond),
+                                Err(err) => {
+                                    InvalidLoaderRuleConditionIssue {
+                                        error_string: RcStr::from(err.to_string()),
+                                        condition: condition.clone(),
+                                        config_file_path: self
+                                            .config_file_path(project_path.clone())
+                                            .owned()
+                                            .await?,
+                                    }
+                                    .resolved_cell()
+                                    .emit();
+                                    None
                                 }
-                                .resolved_cell()
-                                .emit();
-                                None
                             }
                         } else {
                             None

filename: examples/basic-css/next.config.js
patch: @@ -0,0 +1,13 @@
+module.exports = {
+  turbopack: {
+    rules: {
+      "*.svg": {
+        loaders: ["@svgr/webpack"],
+        as: "*.js",
+        condition: {
+          path: /abc/,
+        },
+      },
+    },
+  },
+};