* Map a `GitError` subclass to the standard `git: ` * stderr framing and a deterministic exit code: * * NotARepositoryError, AlreadyInitializedError, * MissingIdentityError, PathOutsideRepoError, * PathspecNotFoundError -> 128 * any other GitError
(subcommand: string, cause: unknown)
| 2127 | * errors and 1 for "command ran but didn't succeed". |
| 2128 | */ |
| 2129 | function mapGitError(subcommand: string, cause: unknown): GitCliResult { |
| 2130 | if (cause instanceof NotARepositoryError) { |
| 2131 | return makeStderr(subcommand, cause.message, 128); |
| 2132 | } |
| 2133 | if (cause instanceof AlreadyInitializedError) { |
| 2134 | return makeStderr(subcommand, cause.message, 128); |
| 2135 | } |
| 2136 | if (cause instanceof MissingIdentityError) { |
| 2137 | return makeStderr(subcommand, cause.message, 128); |
| 2138 | } |
| 2139 | if (cause instanceof PathspecNotFoundError) { |
| 2140 | return makeStderr(subcommand, cause.message, 128); |
| 2141 | } |
| 2142 | if (cause instanceof GitError) { |
| 2143 | return makeStderr(subcommand, cause.message, 1); |
| 2144 | } |
| 2145 | return makeStderr(subcommand, errorMessage(cause), 1); |
| 2146 | } |
| 2147 | |
| 2148 | function makeStderr(subcommand: string, message: string, exitCode: number): GitCliResult { |
| 2149 | return { stdout: "", stderr: `git ${subcommand}: ${message}\n`, exitCode }; |
no test coverage detected