Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: more detailed error message in pass from spec #1329

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions tests/test_pass_from_spec.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from dataclasses import dataclass, field
from typing import Literal

Expand Down Expand Up @@ -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"),
Expand All @@ -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)
6 changes: 5 additions & 1 deletion xdsl/passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}]"
superlopuh marked this conversation as resolved.
Show resolved Hide resolved
)

# instantiate the dataclass using kwargs
return cls(**arg_dict)
Expand Down