Skip to content

Fix usage API parse errors with resilient decoding - #9

Merged
stevensouza merged 1 commit into
mainfrom
stevensouza/fix-usage-api-parse
Apr 7, 2026
Merged

stevensouza merged 1 commit into
mainfrom
stevensouza/fix-usage-api-parse

Conversation

@stevensouza

Copy link
Copy Markdown
Owner

Make UsageWindow.utilization optional by adding a custom Codable decoder that defaults to 0.0 when missing. This prevents DecodingError crashes when the API omits fields.

Changes

  • Add resilient JSON decoding using decodeIfPresent so missing fields don't crash
  • Log raw JSON (truncated preview on success, full response on errors) for schema debugging
  • Log parse errors to Event Log UI, not just NSLog
  • Improve success logs to include all breakdown data (Opus, Sonnet, Cowork, OAuth, Extra)

Fixes recurring "Usage API parse error: The data couldn't be read because it is missing" errors in polling.

🤖 Generated with Claude Code

Make UsageWindow.utilization optional by adding a custom Codable decoder that defaults to 0.0 when missing. This prevents DecodingError crashes when the API omits fields. Also add detailed raw JSON logging (truncated preview on success, full response on error) and log parse errors to the Event Log UI for visibility. Improve success logs to include all returned breakdown data.

Fixes recurring "Usage API parse error: The data couldn't be read because it is missing" errors in polling.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@stevensouza
stevensouza merged commit 06718ee into main Apr 7, 2026
2 checks passed
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