Skip to content

fix(logs): replace .parse() with .safeParse() to prevent ZodError crash on self-hosted#1096

Open
jared-outpost[bot] wants to merge 2 commits into
mainfrom
issue-1095-fix-log-list-zod-crash
Open

fix(logs): replace .parse() with .safeParse() to prevent ZodError crash on self-hosted#1096
jared-outpost[bot] wants to merge 2 commits into
mainfrom
issue-1095-fix-log-list-zod-crash

Conversation

@jared-outpost

@jared-outpost jared-outpost Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

listLogs() and getLogsBatch() in src/lib/api/logs.ts were the only API functions using raw Zod .parse(), which throws an unhandled ZodError when a self-hosted instance returns a non-object response (HTML from a reverse proxy, plain text from an unsupported endpoint). Replaced with .safeParse() + ApiError, matching the pattern used by apiRequestToRegion and organizations.ts.

Added a safeParseResponse() helper that pre-checks typeof data, uses .safeParse(), and attaches Zod issues to Sentry context for diagnostics.

Testing

npx vitest run test/lib/api/logs.test.ts — 6 tests covering string, null, wrong-shape, and valid responses for both listLogs and getLogs. Full API test suite (182 tests) passes.

Closes #1095

…sh on self-hosted

listLogs() and getLogsBatch() used raw .parse() which throws ZodError
when the API returns a non-object response (e.g. HTML from a reverse
proxy or plain text from an unsupported self-hosted endpoint). This was
the only API module using .parse() — all others use .safeParse() via
apiRequestToRegion's schema option.

Added safeParseResponse() helper that:
1. Pre-checks typeof data for early, descriptive errors
2. Uses .safeParse() + wraps failures in ApiError
3. Attaches Zod issues to Sentry context for diagnostics

Fixes #1095
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1096/

Built to branch gh-pages at 2026-06-16 03:26 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 5015 uncovered lines.
✅ Project coverage is 81.19%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.19%    81.19%        —%
==========================================
  Files          383       383         —
  Lines        26651     26659        +8
  Branches     17354     17362        +8
==========================================
+ Hits         21638     21644        +6
- Misses        5013      5015        +2
- Partials      1798      1800        +2

Generated by Codecov Action

@MathurAditya724 MathurAditya724 requested a review from BYK June 12, 2026 12:06
@MathurAditya724 MathurAditya724 marked this pull request as ready for review June 13, 2026 05:24
Comment thread src/lib/api/logs.ts Outdated
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.

Fix: log list crashes with ZodError on self-hosted instances (CLI-20C)

2 participants