Skip to content

Fix parser contract errors - #21

Merged
tudborg merged 1 commit into
mainfrom
fix-parser-contract-errors
Jul 18, 2026
Merged

Fix parser contract errors#21
tudborg merged 1 commit into
mainfrom
fix-parser-contract-errors

Conversation

@tudborg

@tudborg tudborg commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Return parse errors instead of raising for unsupported or malformed parser paths.

  • DLL unsupported control fields now return parse errors
  • TPL fragmented AFL, truncated headers, and unsupported config modes return parse errors
  • ELL unsupported/truncated variants and reserved session encryption modes return parse errors
  • AFL truncated frames return parse errors
  • Crypto wrapper error shape is consistent

Exceptions are still exceptions; no global exception swallowing.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the parsing contract so that unsupported or malformed frames produce structured parse errors (stored in the parse context) instead of raising exceptions, improving crash resistance while keeping true exceptions as exceptions.

Changes:

  • Convert several previously-raising parser paths (DLL control field variants, TPL fragmentation/header/config modes, ELL variants/session modes, AFL truncation) into {:halt, Context.add_error(...)}
  • Add crash-resistance tests asserting specific error shapes for unsupported/truncated inputs
  • Normalize crypto wrapper error returns to a consistent tagged tuple shape

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/crash_resistance_test.exs Adds regression tests ensuring malformed/unsupported frames return parse errors instead of crashing.
lib/exmbus/parser/tpl/configuration_field.ex Returns {:error, ...} for truncated/unsupported configuration field modes instead of raising/matching unsafely.
lib/exmbus/parser/tpl.ex Converts fragmented AFL handling and TPL header parsing to return parse errors (halt with context error).
lib/exmbus/parser/ell/session_number.ex Converts reserved ELL session encryption modes from raise to {:error, ...}.
lib/exmbus/parser/ell.ex Uses with to propagate decode failures into parse errors; adds truncation handling for known ELL CI values.
lib/exmbus/parser/dll/wmbus.ex Propagates unsupported control fields as parse errors and adds a safe fallback for malformed WMbus DLL frames.
lib/exmbus/parser/dll/mbus.ex Propagates unsupported control fields as parse errors and adds a safe fallback for malformed MBus DLL frames.
lib/exmbus/parser/afl.ex Avoids match crashes on truncated AFL by returning parse errors for truncation / non-AFL CI.
lib/exmbus/crypto.ex Wraps crypto exceptions in a tagged error tuple for consistent downstream handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/exmbus/parser/tpl.ex
Comment thread lib/exmbus/crypto.ex
Return parse errors instead of raising for unsupported or malformed parser paths.

- DLL unsupported control fields now return parse errors

- TPL fragmented AFL, truncated headers, and unsupported config modes return parse errors

- ELL unsupported/truncated variants and reserved session encryption modes return parse errors

- AFL truncated frames return parse errors

- Crypto wrapper error shape is consistent

- Add regression coverage for malformed parser inputs

Exceptions are still exceptions; no global exception swallowing.
@agent-mimas
agent-mimas Bot force-pushed the fix-parser-contract-errors branch from cff62e9 to 8d1f1fc Compare July 18, 2026 18:05
@tudborg
tudborg merged commit 1732c62 into main Jul 18, 2026
1 check passed
@tudborg
tudborg deleted the fix-parser-contract-errors branch July 18, 2026 18:07
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.

2 participants