Skip to content

🧹 [code health] fix broad except in analyze-token-usage.py - #6

Merged
pakorn269 merged 1 commit into
mainfrom
fix-bare-except-analyze-token-usage-16657757307016695504
Mar 14, 2026
Merged

pakorn269 merged 1 commit into
mainfrom
fix-bare-except-analyze-token-usage-16657757307016695504

Conversation

@pakorn269

Copy link
Copy Markdown
Owner

Replaced a broad except Exception: clause with specific exceptions (json.JSONDecodeError, KeyError, AttributeError, TypeError) in tests/claude-code/analyze-token-usage.py. This improves maintainability and debuggability by allowing unexpected errors to surface while still handling anticipated data-related issues when parsing session transcripts. Verified the change with sample valid and malformed data.


PR created automatically by Jules for task 16657757307016695504 started by @pakorn269

…-usage.py

Replaced the broad `except Exception:` clause in `tests/claude-code/analyze-token-usage.py` with specific exceptions: `json.JSONDecodeError`, `KeyError`, `AttributeError`, and `TypeError`. This prevents the script from silently ignoring unexpected errors while still safely skipping malformed log entries.

Co-authored-by: pakorn269 <[email protected]>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 14, 2026 01:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the robustness of the Claude Code session transcript token analyzer by narrowing an overly broad exception handler so unexpected failures surface while still tolerating malformed or structurally unexpected JSONL lines.

Changes:

  • Replaced except Exception: with a targeted set of data/parsing-related exceptions during per-line transcript parsing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pakorn269
pakorn269 merged commit 9c137fa into main Mar 14, 2026
4 checks passed
@pakorn269
pakorn269 deleted the fix-bare-except-analyze-token-usage-16657757307016695504 branch March 14, 2026 01:59
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