MCPcopy
hub / github.com/colinhacks/zod / handleResult

Function handleResult

packages/zod/src/v3/types.ts:87–108  ·  view source on GitHub ↗
(
  ctx: ParseContext,
  result: SyncParseReturnType<Output>
)

Source from the content-addressed store, hash-verified

85}
86
87const handleResult = <Input, Output>(
88 ctx: ParseContext,
89 result: SyncParseReturnType<Output>
90): { success: true; data: Output } | { success: false; error: ZodError<Input> } => {
91 if (isValid(result)) {
92 return { success: true, data: result.value };
93 } else {
94 if (!ctx.common.issues.length) {
95 throw new Error("Validation failed but no issues detected.");
96 }
97
98 return {
99 success: false,
100 get error() {
101 if ((this as any)._error) return (this as any)._error as Error;
102 const error = new ZodError(ctx.common.issues);
103 (this as any)._error = error;
104 return (this as any)._error;
105 },
106 };
107 }
108};
109
110export type RawCreateParams =
111 | {

Callers 2

safeParseFunction · 0.85
safeParseAsyncFunction · 0.85

Calls 1

isValidFunction · 0.85

Tested by

no test coverage detected