Skip to content

Guard non-object JSON log lines in discovery (PBM/mixed logs) - #2

Open
zelmario wants to merge 1 commit into
mainfrom
fix/nondict-log-line
Open

Guard non-object JSON log lines in discovery (PBM/mixed logs)#2
zelmario wants to merge 1 commit into
mainfrom
fix/nondict-log-line

Conversation

@zelmario

Copy link
Copy Markdown
Owner

Problem

_discover_log_file parses each line and immediately reads obj.get("attr", {}):

obj = json.loads(line)
self.deep_discover(obj)
attr = obj.get("attr", {})   # <- AttributeError if obj isn't a dict

A log line can be valid JSON that is not an object — a bare quoted string or a number. These show up in PBM logs and other mixed container logs. str/int have no .get, so this raises AttributeError, which is not a JSONDecodeError, so it escapes the except and aborts discovery for the entire file.

Fix

Guard the attr lookup with isinstance(obj, dict). deep_discover already no-ops on non-dict input, so bare-scalar lines are simply skipped (nothing to discover in them anyway).

Verified: a file mixing a bare-string line, a number line, and a normal structured line now processes all lines without crashing.

🤖 Generated with Claude Code

…d logs)

_discover_log_file did `obj = json.loads(line)` then `obj.get("attr")`.
A log line can be valid JSON that is NOT an object — a bare quoted string
or number, common in PBM and mixed container logs. `.get` then raises
AttributeError, which isn't a JSONDecodeError, so it escapes the except
and aborts discovery for the whole file.

Guard the attr lookup with `isinstance(obj, dict)`. deep_discover already
no-ops on non-dict input, so bare-scalar lines are simply skipped.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant