From 49544054ebe525a1f0f8bc132ad0bf036ce3f02a Mon Sep 17 00:00:00 2001 From: Fiddle-Config Team Date: Tue, 21 Oct 2025 06:53:56 -0700 Subject: [PATCH] Make the error message when an unrecognized attribute is used in a Buildable more useful. We often deal with configs with 1k+ lines and this common error message puts the missing attribute at the top before printing out the entire Buildable. At best, it is difficult to figure out the missing attribute, but usually, it is beyond the pagination limit. This change explicitly lists the Buildable's qualified name and missing attribute at the end so it is easy to identify. PiperOrigin-RevId: 822097405 --- fiddle/_src/config.py | 6 +++++- fiddle/_src/config_test.py | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/fiddle/_src/config.py b/fiddle/_src/config.py index a015767e..9d4a07b7 100644 --- a/fiddle/_src/config.py +++ b/fiddle/_src/config.py @@ -353,7 +353,11 @@ def __getattr__(self, name: str): ) if param is not None and param.default is not param.empty: return param.default - msg = f"No parameter '{name}' has been set on {self!r}." + msg = ( + f"No parameter '{name}' has been set on {self!r} " + f"(Buildable='{self.__fn_or_cls__.__qualname__}', missing " + f"parameter='{name}')." + ) # TODO(b/219988937): Implement an edit distance function and display valid # attributes that are close to `name`. if hasattr(self.__fn_or_cls__, name): diff --git a/fiddle/_src/config_test.py b/fiddle/_src/config_test.py index 7e123cbf..4510b97d 100644 --- a/fiddle/_src/config_test.py +++ b/fiddle/_src/config_test.py @@ -843,8 +843,11 @@ def test_repr_varkwargs(self): def test_nonexistent_attribute_error(self): class_config = fdl.Config(SampleClass, 1) - expected_msg = (r"No parameter 'nonexistent_arg' has been set on " - r'\.') + expected_msg = ( + r"No parameter 'nonexistent_arg' has been set on " + r' \(Buildable=' + r"'SampleClass', missing parameter='nonexistent_arg'\)." + ) with self.assertRaisesRegex(AttributeError, expected_msg): getattr(class_config, 'nonexistent_arg')