Skip to content

fix(netusage): handle exceptions during timestamp conversion#1388

Open
Tokenzrey wants to merge 1 commit intoabrignoni:mainfrom
Tokenzrey:fix/netusage/handle-timestamp-exceptions
Open

fix(netusage): handle exceptions during timestamp conversion#1388
Tokenzrey wants to merge 1 commit intoabrignoni:mainfrom
Tokenzrey:fix/netusage/handle-timestamp-exceptions

Conversation

@Tokenzrey
Copy link

@Tokenzrey Tokenzrey commented Dec 8, 2025

This PR fixes a critical bug in netusage.py that causes the artifact parser to crash when processing netusage.sqlite databases containing invalid or NULL timestamps.

Previously, the parser would fail completely upon encountering a single invalid timestamp string (e.g., an empty string returned by SQLite's datetime function), resulting in total data loss for this artifact. This update implements defensive programming to handle these exceptions gracefully.

Changes

  • Added: try-except blocks around convert_ts_human_to_utc calls in netusage.py.
  • Logic: If a ValueError or TypeError occurs during conversion, the timestamp is set to 'N/A' instead of crashing the script.
  • Result: The parser now processes all valid rows and marks invalid timestamps clearly, ensuring maximum data extraction.

Verification & Testing

I have created a comprehensive test suite (test_netusage_fix.py) to verify the fix and ensure no regressions.

  • Test Suite: 5/5 tests passed.
  • Scenarios Covered:
    • Invalid Timestamp from SQLite (Empty strings/NULLs).
    • Valid Timestamp Conversion (Regression test).
    • None Value Handling.
    • Full Row Processing (Simulation of the fixed loop).
    • Comparison of Original (Crashes) vs. Fixed (Handles gracefully) code.

Test Output Summary:

TEST SUMMARY
================================================================================
Invalid Timestamp from SQLite..................... [PASS]
Valid Timestamp Regression........................ [PASS]
None Value Handling............................... [PASS]
Full Row Processing (Fixed)....................... [PASS]
Original vs Fixed Code............................ [PASS]
================================================================================
Total: 5/5 tests passed
[SUCCESS] ALL TESTS PASSED - Fix is working correctly!

Checklist

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have verified the fix with a local test script.
  • The changes generate no new warnings.

Related Issues

Closes #1389

@Tokenzrey Tokenzrey closed this Dec 8, 2025
@Tokenzrey Tokenzrey reopened this Dec 8, 2025
@Tokenzrey Tokenzrey changed the title fix: Handle exceptions for timestamp conversion in netusage artifact fix(netusage): handle exceptions during timestamp conversion Dec 8, 2025
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.

[Bug] netusage artifact parser crashes on invalid timestamp values

1 participant