fix(logs): replace .parse() with .safeParse() to prevent ZodError crash on self-hosted#1096
Open
jared-outpost[bot] wants to merge 2 commits into
Open
fix(logs): replace .parse() with .safeParse() to prevent ZodError crash on self-hosted#1096jared-outpost[bot] wants to merge 2 commits into
jared-outpost[bot] wants to merge 2 commits into
Conversation
…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
Contributor
|
Contributor
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 5015 uncovered lines. 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 +2Generated by Codecov Action |
BYK
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
listLogs()andgetLogsBatch()insrc/lib/api/logs.tswere the only API functions using raw Zod.parse(), which throws an unhandledZodErrorwhen 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 byapiRequestToRegionandorganizations.ts.Added a
safeParseResponse()helper that pre-checkstypeof 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 bothlistLogsandgetLogs. Full API test suite (182 tests) passes.Closes #1095