Skip to content

preserve JSON entries with invalid numeric timestamps - #31

Draft
HrachShah wants to merge 1 commit into
mainfrom
patch/ignore-unrepresentable-json-timestamps
Draft

preserve JSON entries with invalid numeric timestamps#31
HrachShah wants to merge 1 commit into
mainfrom
patch/ignore-unrepresentable-json-timestamps

Conversation

@HrachShah

@HrachShah HrachShah commented Jul 30, 2026

Copy link
Copy Markdown
Owner

What does this change do?

JSON log records with numeric timestamps outside the platform datetime range are still returned as parsed entries, with their timestamp left unset.

Why is this needed?

A single malformed or unrepresentable timestamp should not discard an otherwise useful log record or abort parsing the file.

Testing

  • PYTHONPATH=src pytest -q tests/test_parsers.py -o addopts="" --disable-warnings — 24 passed
  • git diff --check

Drafted with GPT-5.6 Luna; reviewed by the repository owner.

Summary by Sourcery

Handle JSON log records whose numeric timestamps are outside the platform datetime range without discarding the entries.

Bug Fixes:

  • Prevent JSON log parsing from failing when encountering unrepresentable numeric timestamps by returning entries with an unset timestamp field.

Tests:

  • Add parametrized tests verifying JSON logs with extremely large or otherwise unrepresentable numeric timestamps still produce parsed entries with no timestamp set.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7db9caf6-6908-4414-a456-b1d6a120d29a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

JSON log parsing is updated so that numeric timestamps that cannot be represented as datetimes no longer cause parsing failures; instead, the log entry is returned with a null timestamp, and tests are added to cover these cases.

Sequence diagram for JSON numeric timestamp extraction with overflow handling

sequenceDiagram
    participant JsonLogParser
    participant _extract_timestamp
    participant datetime

    JsonLogParser->>_extract_timestamp: _extract_timestamp(data)
    _extract_timestamp->>_extract_timestamp: [field has numeric value]
    _extract_timestamp->>datetime: fromtimestamp(value or value/1000)
    alt timestamp convertible
        datetime-->>_extract_timestamp: datetime
        _extract_timestamp-->>JsonLogParser: return parsed datetime
    else timestamp not representable
        datetime-->>_extract_timestamp: OverflowError/OSError/ValueError
        _extract_timestamp-->>JsonLogParser: return None (timestamp unset)
    end
Loading

File-Level Changes

Change Details Files
Make numeric timestamp extraction resilient to unrepresentable values by returning entries with a null timestamp instead of failing.
  • Wrap numeric timestamp handling in a try/except block to catch datetime conversion errors.
  • Use milliseconds vs seconds conversion as before, but ignore values that raise OverflowError, OSError, or ValueError.
  • Leave the timestamp unset (return None) when numeric conversion fails while still allowing the entry to be parsed.
src/log_analyzer_cli/parsers/json_log.py
Add tests ensuring JSON entries with extremely large or otherwise unrepresentable numeric timestamps are parsed and returned with no timestamp set.
  • Introduce a parametrized test that feeds very large positive, very large negative, and large float timestamps into the JSON parser.
  • Assert that parsing succeeds (entry is not None) and timestamp is None for these malformed numeric values.
tests/test_parsers.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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