Skip to content

Fix errors for malformed LPM and range matches - #163

Merged
jafingerhut merged 1 commit into
p4lang:mainfrom
sillage-hjj:fix/match-input-error-messages
Sep 6, 2026
Merged

jafingerhut merged 1 commit into
p4lang:mainfrom
sillage-hjj:fix/match-input-error-messages

Conversation

@sillage-hjj

Copy link
Copy Markdown
Contributor

Fixes #162

Problem

Malformed LPM prefix lengths and range expressions, such as 10.0.0.0/abc and 10..20..30, raise AttributeError: 'UserError' object has no attribute 'format' instead of the intended UserError explaining the invalid input.

Both error handlers call .format() on a UserError instance rather than on the message string. Since the exception object has no such method, the resulting AttributeError hides the intended diagnostic.

Changes

  • Adjust the parentheses to format the message strings before constructing UserError.
  • Add four regression cases covering non-integer and empty LPM prefix lengths, and missing and extra range separators. Each case checks the exception type and the complete error message.

Testing

  • All four new regression cases fail with the expected AttributeError against the unmodified upstream implementation.

AI assistance was used to identify and reproduce the issue and regression tests, translate the contributor's description.

Format the diagnostic strings before constructing UserError so malformed
prefix lengths and ranges produce the intended input errors. Add four
regression cases covering both exception handlers and their messages.

Refs #162

AI assistance was used to identify and reproduce the issue and prepare
the patch, regression tests, and this commit message.

Signed-off-by: Jiajun He <80980027+sillage-hjj@users.noreply.github.com>
@jafingerhut
jafingerhut merged commit eee9e74 into p4lang:main Sep 6, 2026
4 checks passed
@sillage-hjj
sillage-hjj deleted the fix/match-input-error-messages branch September 6, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed LPM and range matches raise AttributeError

2 participants