buck2 icon indicating copy to clipboard operation
buck2 copied to clipboard

Print target when selects fail to match on toolchain targets

Open thetimmorland opened this issue 6 months ago • 0 comments

When a select expression fails to match on a toolchain target, the error message tells you the name of attribute which failed to match but not the target that attribute was on:

BUILD FAILED
configuring attr `compiler_flags`

The below patch modifies this message to include the target.

diff --git a/app/buck2_configured/src/nodes/calculation.rs b/app/buck2_configured/src/nodes/calculation.rs
index b3e0e9686f..1cee0384f3 100644
--- a/app/buck2_configured/src/nodes/calculation.rs
+++ b/app/buck2_configured/src/nodes/calculation.rs
@@ -723,7 +723,13 @@ async fn gather_deps(
 
     let mut traversal = Traversal::default();
     for a in target_node.attrs(AttrInspectOptions::All) {
-        let configured_attr = a.configure(attr_cfg_ctx)?;
+        let configured_attr = a.configure(attr_cfg_ctx).with_context(|| {
+            format!(
+                "configuring attr `{}` for target `{}`",
+                a.name,
+                target_node.label()
+            )
+        })?;
         configured_attr.traverse(target_node.label().pkg(), &mut traversal)?;
     }
 
diff --git a/app/buck2_node/src/attrs/coerced_attr_full.rs b/app/buck2_node/src/attrs/coerced_attr_full.rs
index b90008c53f..712469a436 100644
--- a/app/buck2_node/src/attrs/coerced_attr_full.rs
+++ b/app/buck2_node/src/attrs/coerced_attr_full.rs
@@ -31,10 +31,7 @@ impl<'a> CoercedAttrFull<'a> {
         Ok(ConfiguredAttrFull {
             name: self.name,
             attr: self.attr,
-            value: self
-                .value
-                .configure(self.attr.coercer(), ctx)
-                .with_context(|| format!("configuring attr `{}`", self.name))?,
+            value: self.value.configure(self.attr.coercer(), ctx)?,
         })
     }

thetimmorland avatar Aug 05 '24 17:08 thetimmorland