From 3b1e94b626d2e98c0c5dca0134839ba3cca2bcb0 Mon Sep 17 00:00:00 2001 From: Sasha Lopoukhine Date: Mon, 17 Jul 2023 14:40:27 +0100 Subject: [PATCH 1/2] misc: more detailed error message in pass from spec --- tests/test_pass_from_spec.py | 5 +++-- xdsl/passes.py | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_pass_from_spec.py b/tests/test_pass_from_spec.py index 80f1a38405..f92e78f4ad 100644 --- a/tests/test_pass_from_spec.py +++ b/tests/test_pass_from_spec.py @@ -1,3 +1,4 @@ +import re from dataclasses import dataclass, field from typing import Literal @@ -82,7 +83,7 @@ def test_pass_instantiation(): (PipelinePassSpec("simple", {}), 'requires argument "a"'), ( PipelinePassSpec("simple", {"a": [1], "no": []}), - 'Unrecognised pass arguments "no"', + 'Pass arguments ["no"] not found in ["a", "b"]', ), (PipelinePassSpec("simple", {"a": []}), "Argument must contain a value"), (PipelinePassSpec("simple", {"a": ["test"]}), "Incompatible types"), @@ -96,5 +97,5 @@ def test_pass_instantiation_error(spec: PipelinePassSpec, error_msg: str): """ Test all possible failure modes in pass instantiation """ - with pytest.raises(Exception, match=error_msg): + with pytest.raises(Exception, match=re.escape(error_msg)): SimplePass.from_pass_spec(spec) diff --git a/xdsl/passes.py b/xdsl/passes.py index d7a9b8a9ce..442b7e7d08 100644 --- a/xdsl/passes.py +++ b/xdsl/passes.py @@ -92,7 +92,11 @@ def from_pass_spec(cls: type[ModulePassT], spec: PipelinePassSpec) -> ModulePass # if not all args were removed we raise an error if len(spec.args) != 0: - raise ValueError(f'Unrecognised pass arguments "{", ".join(spec.args)}"') + arguments_str = ", ".join(f'"{arg}"' for arg in spec.args) + fields_str = ", ".join(f'"{field.name}"' for field in fields) + raise ValueError( + f"Pass arguments [{arguments_str}] not found in [{fields_str}]" + ) # instantiate the dataclass using kwargs return cls(**arg_dict) From 483bd9fd9a40ffb12ad93999b1d120e0664558cf Mon Sep 17 00:00:00 2001 From: Sasha Lopoukhine Date: Tue, 25 Jul 2023 10:43:14 +0100 Subject: [PATCH 2/2] improve diagnostic --- tests/test_pass_from_spec.py | 2 +- xdsl/passes.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_pass_from_spec.py b/tests/test_pass_from_spec.py index f92e78f4ad..525e5c9974 100644 --- a/tests/test_pass_from_spec.py +++ b/tests/test_pass_from_spec.py @@ -83,7 +83,7 @@ def test_pass_instantiation(): (PipelinePassSpec("simple", {}), 'requires argument "a"'), ( PipelinePassSpec("simple", {"a": [1], "no": []}), - 'Pass arguments ["no"] not found in ["a", "b"]', + 'Provided arguments ["no"] not found in expected pass arguments ["a", "b"]', ), (PipelinePassSpec("simple", {"a": []}), "Argument must contain a value"), (PipelinePassSpec("simple", {"a": ["test"]}), "Incompatible types"), diff --git a/xdsl/passes.py b/xdsl/passes.py index 442b7e7d08..9dfe7d0cb0 100644 --- a/xdsl/passes.py +++ b/xdsl/passes.py @@ -95,7 +95,8 @@ def from_pass_spec(cls: type[ModulePassT], spec: PipelinePassSpec) -> ModulePass arguments_str = ", ".join(f'"{arg}"' for arg in spec.args) fields_str = ", ".join(f'"{field.name}"' for field in fields) raise ValueError( - f"Pass arguments [{arguments_str}] not found in [{fields_str}]" + f"Provided arguments [{arguments_str}] not found in expected pass " + f"arguments [{fields_str}]" ) # instantiate the dataclass using kwargs