-
-
Notifications
You must be signed in to change notification settings - Fork 11
refactor(cli): remove remaining zod usage, migrate to valibot #1389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ import { zstdCompress as zstdCompressCb } from "node:zlib"; | |
| import { parseSentryLinkHeader } from "@sentry/api"; | ||
| // biome-ignore lint/performance/noNamespaceImport: Sentry SDK recommends namespace import | ||
| import * as Sentry from "@sentry/node-core/light"; | ||
| import type { z } from "zod"; | ||
| import { type GenericSchema, safeParse } from "valibot"; | ||
|
|
||
| import { extractRequiredScopes } from "../api-scope.js"; | ||
| import { getActiveEnvVarName, isEnvTokenActive } from "../db/auth.js"; | ||
|
|
@@ -189,8 +189,8 @@ export type ApiRequestOptions<T = unknown> = { | |
| bodyEncoding?: "zstd"; | ||
| /** Query parameters. String arrays create repeated keys (e.g., tags=1&tags=2) */ | ||
| params?: Record<string, string | number | boolean | string[] | undefined>; | ||
| /** Optional Zod schema for runtime validation of response data */ | ||
| schema?: z.ZodType<T>; | ||
| /** Optional valibot schema for runtime validation of response data */ | ||
| schema?: GenericSchema<unknown, T>; | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -524,23 +524,29 @@ export async function apiRequestToRegion<T>( | |
| } | ||
|
|
||
| if (schema) { | ||
| const result = schema.safeParse(data); | ||
| const result = safeParse(schema, data); | ||
| if (!result.success) { | ||
| // Attach structured Zod issues to the Sentry event so we can diagnose | ||
| // exactly which field(s) failed validation — the ApiError.detail string | ||
| // alone may not be visible in the Sentry issue overview. | ||
| Sentry.setContext("zod_validation", { | ||
| // Attach structured validation issues to the Sentry event so we can | ||
| // diagnose exactly which field(s) failed validation — the ApiError.detail | ||
| // string alone may not be visible in the Sentry issue overview. | ||
| // Strip valibot issues to metadata only (path/type/message) before | ||
| // attaching — full issues embed the raw failing `input` value. | ||
| Sentry.setContext("schema_validation", { | ||
| endpoint, | ||
| status: response.status, | ||
| issues: result.error.issues.slice(0, 10), | ||
| issues: result.issues.slice(0, 10).map((i) => ({ | ||
| path: i.path, | ||
| type: i.type, | ||
| message: i.message, | ||
| })), | ||
| }); | ||
| throw new ApiError( | ||
| `Unexpected response format from ${endpoint}`, | ||
| response.status, | ||
| result.error.message | ||
| result.issues.map((issue) => issue.message).join(", ") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validation errors omit failing field pathsLow Severity Valibot issue messages do not include their paths, so joining only Additional Locations (2)Reviewed by Cursor Bugbot for commit 0108cd2. Configure here. |
||
| ); | ||
| } | ||
| return { data: result.data, headers: response.headers }; | ||
| return { data: result.output, headers: response.headers }; | ||
| } | ||
|
|
||
| return { data: data as T, headers: response.headers }; | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.