( ctx: ParseContext, result: SyncParseReturnType<Output> )
| 85 | } |
| 86 | |
| 87 | const 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 | |
| 110 | export type RawCreateParams = |
| 111 | | { |
no test coverage detected