Fix parser contract errors - #21
Merged
Merged
Conversation
There was a problem hiding this comment.
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.
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
Bot
force-pushed
the
fix-parser-contract-errors
branch
from
July 18, 2026 18:05
cff62e9 to
8d1f1fc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Return parse errors instead of raising for unsupported or malformed parser paths.
Exceptions are still exceptions; no global exception swallowing.