Fix result_parser: null body guard, explicit dispatch, TypeError messages, dead code - #152
Open
t0kubetsu wants to merge 1 commit into
Open
Fix result_parser: null body guard, explicit dispatch, TypeError messages, dead code#152t0kubetsu wants to merge 1 commit into
t0kubetsu wants to merge 1 commit into
Conversation
…ages, dead code removal
- Add `body = doc.get("body") or {}` and `ports = body.get("ports") or []`
guards in `parse_json` to prevent AttributeError/TypeError on missing body
- Replace `globals()[action]` with `_PARSER_DISPATCH` explicit dict for safe,
auditable parser function lookup; add `hsh` stub for completeness
- Replace bare `raise TypeError` with descriptive messages; fix E713 style
(`not x in y` -> `x not in y`)
- Rename loop variable `script` to `script_key`/`script_data` to eliminate
shadowing of the iteration variable
- Remove dead `insensitive()` function (not in ALLOW, not imported anywhere)
Fixes D4-project#145
t0kubetsu
force-pushed
the
fix/result-parser
branch
from
June 2, 2026 09:15
8fe4d67 to
91764bf
Compare
Contributor
Author
|
Fixed hsh() stub: changed NotImplementedError to return {} — hsh is in default_parsing so raising would crash the export tick for documents with http-header.output. |
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.
Summary
Fixes #145. Three correctness bugs and two code-quality issues in
result_parser.py.Changes
Null body guard
parse_jsonchained.get("body").get(...)without null guards. Any document with a missing or Nonebodykey raisedTypeError/AttributeError, crashing the export tick. Now extracted tobody = doc.get("body") or {}andports = body.get("ports") or []at the top of the function.Explicit dispatch dict
globals()[action]was used to look up parser functions. Replaced with_PARSER_DISPATCH, a module-level dict explicitly mapping eachALLOW-listed name to its function. Prevents silent divergence betweenALLOWandglobals(). Added ahshstub (NotImplementedError) so the table is complete.TypeError messages
Bare
raise TypeError(no message, no instance) at lines 621 and 633 replaced with descriptive messages. Also fixed ruff E713:not x in y→x not in y.Loop variable shadowing
Loop variable
scriptwas immediately rebound to the dict value on the next line, producing a confusingfor script in body: ... script = body.get(script)pattern. Renamed toscript_key/script_data.Dead code removal
insensitive()function removed — not inALLOW, not imported anywhere, unreachable since v0.2606.0.Test plan
body=None— verify export tick does not crashportskey — verify graceful handlingALLOWremain callable via_PARSER_DISPATCH