MCPcopy Create free account
hub / github.com/cloudflare/computer / mapGitError

Function mapGitError

packages/computer/src/git/cli.ts:2129–2146  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

2127 * errors and 1 for "command ran but didn't succeed".
2128 */
2129function 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
2148function makeStderr(subcommand: string, message: string, exitCode: number): GitCliResult {
2149 return { stdout: "", stderr: `git ${subcommand}: ${message}\n`, exitCode };

Callers 15

runDiffFunction · 0.85
runInitFunction · 0.85
runStatusFunction · 0.85
runAddFunction · 0.85
runRmFunction · 0.85
runCommitFunction · 0.85
runLogFunction · 0.85
runShowFunction · 0.85
runRevParseFunction · 0.85
runSymbolicRefFunction · 0.85
runLsFilesFunction · 0.85
runLsTreeFunction · 0.85

Calls 2

makeStderrFunction · 0.85
errorMessageFunction · 0.70

Tested by

no test coverage detected