Skip to content

fix: JsonParser crash without dict config, EventID 0 without message - #359

Open
viktorbeck98 wants to merge 3 commits into
developmentfrom
fix/json-parser-config-eventid
Open

viktorbeck98 wants to merge 3 commits into
developmentfrom
fix/json-parser-config-eventid

Conversation

@viktorbeck98

@viktorbeck98 viktorbeck98 commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Task

Closes #357

Description

Two bugs in JsonParser, both from the issue.

1. AttributeError when the config is not a dictionary. The content parser was only created inside if isinstance(config, dict):. With JsonParser() or a JsonParserConfig object the attribute never existed, and the first log with a message field crashed.

  • A non-dict config now gets a MatcherParser() without templates, so the message comes back as <Not Found> / -1.
  • The issue allows either this or a clear error on creation. I chose this because a config object only holds the name of the content parser, and the basic docs example and the existing tests build the parser without a dict.

2. Logs without a message field got EventID 0. parse() started from a hardcoded 0, which is also the ID of the first template.

  • The default is now -1 with the template <Not Found>, the same as a message that matches no template.

Things to check when reviewing:

  • The template_not_found rule in rule_detector.py alerts on EventID == -1, so it now fires for every JSON log without a message field.
  • A log without a message and a message that matches no template now share -1. If they should be told apart, that needs a separate ID.
  • Not changed here: a message that is a number, object or list raises TypeError, and an empty, null or 0 message is treated as no message.

How Has This Been Tested?

  • 2 new tests, and test_parse_json_without_message updated: it asserted the old EventID 0.
  • The 3 tests fail without the source change and pass with it.
  • Full suite passes (928 passed, 82 skipped).
  • The reproduction script from the issue now prints no error, -1 for the log without a message and 0 for the first template.

Checklist

  • This Pull-Request goes to the development branch.
  • I have successfully run prek locally.
  • I have added tests to cover my changes.
  • I have linked the issue-id to the task-description.
  • I have performed a self-review of my own code.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

A JsonParserConfig object (or the default config) left the parser without
a content parser, so the first log with a message field raised
AttributeError. It now gets a MatcherParser without templates.

Logs without a message field got EventID 0, the ID of the first template.
They now get EventID -1 and the template <Not Found>, like any log that
matches no template.

Closes #357

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from development to main October 13, 2026 07:29
@thorinaboenke
thorinaboenke changed the base branch from main to development October 13, 2026 09:58
@thorinaboenke

thorinaboenke commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

@viktorbeck98 is that fine like this? "A log without a message and a message that matches no template now share -1"
-> json logs with out message alert will then trigger RuleDetector R001?
"A non-dict config now gets a MatcherParser() without templates" -> everything /with message and without message field) will come back indiscriminately with id -1? should there at least be a warning for the user?

@viktorbeck98

Copy link
Copy Markdown
Collaborator Author

@thorinaboenke we could also differentiate between the two cases. You're right, it's probably cleaner. We could use "-2" for when no message field is given

viktorbeck98 and others added 2 commits October 15, 2026 16:37
Follow the schema field rename (#363) in the JsonParser fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A log without a message field now gets eventID -2 and an empty template,
so it no longer shares -1 with a message that matches no template (and no
longer triggers the template_not_found rule). A parser whose content
parser has no templates logs one warning at the first message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@viktorbeck98

Copy link
Copy Markdown
Collaborator Author

@thorinaboenke I addressed your comments

@viktorbeck98
viktorbeck98 requested a review from ipmach October 16, 2026 13:39

This branch has not been deployed

No deployments
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