Skip to content

Conversation

@simeonlee
Copy link
Member

@simeonlee simeonlee commented Jan 12, 2026

Summary

Adds Zod schema validation for InfraErrorData, replacing the manual type guard with schema-based validation. This ensures runtime validation matches the TypeScript type definition.

Changes

  • Add InfraErrorDataSchema using z.discriminatedUnion for type-safe validation
  • Replace manual isInfraErrorData type guard with InfraErrorDataSchema.safeParse()
  • Infer InfraErrorData type from schema to keep type and runtime validation in sync

Before

export type InfraErrorData =
  | { errorType: typeof InfraErrorType.GatewayUnavailable }
  | { errorType: typeof InfraErrorType.GatewayAuthFailed }
  // ... manually defined

export function isInfraErrorData(value: unknown): value is InfraErrorData {
  return (
    typeof value === "object" &&
    value !== null &&
    "errorType" in value &&
    typeof value.errorType === "string" &&
    Object.values(InfraErrorType).includes(value.errorType as InfraErrorType)
  );
  // Manual validation - could drift from type definition
}

After

export const InfraErrorDataSchema = z.discriminatedUnion("errorType", [
  z.object({ errorType: z.literal(InfraErrorType.GatewayUnavailable) }),
  z.object({ errorType: z.literal(InfraErrorType.GatewayAuthFailed) }),
  // ... schema is single source of truth
]);

export type InfraErrorData = z.infer<typeof InfraErrorDataSchema>;

export function isInfraErrorData(value: unknown): value is InfraErrorData {
  return InfraErrorDataSchema.safeParse(value).success;
  // Validation always matches type definition
}

PR Stack

PR Description Status
[1a] Error utilities Base PR
→ This PR Zod validation 🚧 Draft

Test plan

  • Typecheck passes
  • Lint passes
  • All 50 error tests pass

Important

Add Zod schema validation for InfraErrorData and serialized error schemas in errors.ts for improved runtime validation and error handling.

  • Validation:
    • Add InfraErrorDataSchema using z.discriminatedUnion for type-safe validation in errors.ts.
    • Replace manual isInfraErrorData type guard with InfraErrorDataSchema.safeParse().
  • Type Inference:
    • Infer InfraErrorData type from InfraErrorDataSchema to ensure type and runtime validation sync.
  • Serialized Error Schemas:
    • Add schemas for serialized errors: SerializedGatewayConnectionErrorSchema, SerializedAuthenticationErrorSchema, SerializedRouteNotFoundErrorSchema, SerializedClickHouseErrorSchema, and SerializedAutopilotUnavailableErrorSchema in errors.ts.
  • Error Functions:
    • Update isGatewayConnectionError, isAuthenticationError, isGatewayEndpointNotFoundError, isClickHouseError, and isAutopilotUnavailableError to use respective serialized schemas in errors.ts.

This description was created by Ellipsis for a506597. You can customize this summary. It will automatically update as commits are pushed.

@simeonlee simeonlee force-pushed the simeonlee/error-boundaries-1a-zod-validation branch from f5826c5 to 8ae51b2 Compare January 12, 2026 18:16
Base automatically changed from simeonlee/error-boundaries-1a-error-utilities to main January 12, 2026 18:46
- Add InfraErrorDataSchema using z.discriminatedUnion for type-safe validation
- Replace manual isInfraErrorData type guard with Zod safeParse
- Infer InfraErrorData type from schema to keep type and validation in sync

This ensures runtime validation matches the TypeScript type definition,
reducing the risk of mismatches between the two.
- Add schemas for serialized error shapes that cross React Router boundary:
  - SerializedGatewayConnectionErrorSchema
  - SerializedAuthenticationErrorSchema
  - SerializedRouteNotFoundErrorSchema
  - SerializedClickHouseErrorSchema
  - SerializedAutopilotUnavailableErrorSchema
- Replace manual object property checks with Zod safeParse()
- Reduces boilerplate while keeping validation centralized

The schemas validate error objects after serialization where instanceof
checks fail. Each type guard still uses instanceof for server-side checks.
@simeonlee simeonlee force-pushed the simeonlee/error-boundaries-1a-zod-validation branch from e09e8af to a506597 Compare January 12, 2026 19:00
@simeonlee
Copy link
Member Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@simeonlee simeonlee changed the title WIP: [Error Boundaries] Add Zod schema for InfraErrorData validation [Error Boundaries] Add Zod schema for InfraErrorData validation Jan 12, 2026
@simeonlee simeonlee marked this pull request as ready for review January 12, 2026 19:07
@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. 🚀

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@GabrielBianconi GabrielBianconi added this pull request to the merge queue Jan 12, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 12, 2026
@GabrielBianconi GabrielBianconi added this pull request to the merge queue Jan 12, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 13, 2026
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.

3 participants