| 12 | } |
| 13 | |
| 14 | function handleError(error: unknown, reply: any) { |
| 15 | if (error instanceof ZodError) { |
| 16 | reply.code(400); |
| 17 | return { error: 'Validation failed', code: 'VALIDATION_ERROR', details: error.errors }; |
| 18 | } |
| 19 | |
| 20 | if (error instanceof GitUnavailableError) { |
| 21 | reply.code(400); |
| 22 | return { |
| 23 | error: 'Git is not available for this working directory', |
| 24 | code: 'GIT_UNAVAILABLE', |
| 25 | workingDir: error.workingDir, |
| 26 | }; |
| 27 | } |
| 28 | |
| 29 | console.error('[git] Unhandled error:', error); |
| 30 | reply.code(500); |
| 31 | return { error: 'Internal server error', code: 'INTERNAL_ERROR' }; |
| 32 | } |
| 33 | |
| 34 | /** execFile promisified with timeout */ |
| 35 | function execGit(cwd: string, args: string[]): Promise<string> { |