Add "(no output)" fallback to all git error messages

The helpers already handled empty stderr but the git module did not,
leading to confusing error messages with a trailing colon and no detail.
This commit is contained in:
Chris Wanstrath 2026-04-10 08:54:17 -07:00
parent 374454f0fb
commit b4d0d9e948
2 changed files with 13 additions and 7 deletions

View File

@ -128,7 +128,7 @@ export async function resolveConflicts(
)
if (resolved.exitCode !== 0) {
const stderr = resolved.stderr.toString().trim()
const stderr = resolved.stderr.trim()
throw new Error(`Claude failed to resolve ${file}: ${stderr || "(no output)"}`)
}

View File

@ -72,7 +72,8 @@ export async function createWorktree(branch: string, worktreePath: string, cwd:
}
if (result.exitCode !== 0) {
if (switchedFromBranch) await checkout(branch, cwd).catch(() => {})
throw new Error(`Failed to create worktree for "${branch}": ${result.stderr.toString().trim()}`)
const stderr = result.stderr.toString().trim()
throw new Error(`Failed to create worktree for "${branch}": ${stderr || "(no output)"}`)
}
return { branchCreated: exists !== "local" }
}
@ -98,7 +99,8 @@ export async function deleteLocalBranch(branch: string, cwd: string): Promise<vo
export async function checkout(branch: string, cwd: string): Promise<void> {
const result = await $`git checkout ${branch}`.cwd(cwd).nothrow().quiet()
if (result.exitCode !== 0) {
throw new Error(`Failed to checkout branch "${branch}": ${result.stderr.toString().trim()}`)
const stderr = result.stderr.toString().trim()
throw new Error(`Failed to checkout branch "${branch}": ${stderr || "(no output)"}`)
}
}
@ -117,7 +119,8 @@ export async function merge(branch: string, cwd: string, opts?: { squash?: boole
// Not a conflict — some other merge failure
const label = opts?.squash ? "squash-merge" : "merge"
throw new Error(`Failed to ${label} branch "${branch}": ${result.stderr.toString().trim()}`)
const stderr = result.stderr.toString().trim()
throw new Error(`Failed to ${label} branch "${branch}": ${stderr || "(no output)"}`)
}
/** Return the staged diff as text. */
@ -129,7 +132,8 @@ export async function diffStaged(cwd: string): Promise<string> {
export async function commit(message: string, cwd: string): Promise<void> {
const result = await $`git commit -m ${message}`.cwd(cwd).nothrow().quiet()
if (result.exitCode !== 0) {
throw new Error(`Failed to commit: ${result.stderr.toString().trim()}`)
const stderr = result.stderr.toString().trim()
throw new Error(`Failed to commit: ${stderr || "(no output)"}`)
}
}
@ -155,7 +159,8 @@ export async function stageFile(file: string, cwd: string): Promise<void> {
export async function commitMerge(cwd: string): Promise<void> {
const result = await $`git commit --no-edit`.cwd(cwd).nothrow().quiet()
if (result.exitCode !== 0) {
throw new Error(`Failed to commit merge: ${result.stderr.toString().trim()}`)
const stderr = result.stderr.toString().trim()
throw new Error(`Failed to commit merge: ${stderr || "(no output)"}`)
}
}
@ -193,7 +198,8 @@ export async function rebaseContinue(cwd: string): Promise<string[]> {
const files = unmerged.trim().split("\n").filter(Boolean)
if (files.length > 0) return files
throw new Error(`Rebase --continue failed: ${result.stderr.toString().trim()}`)
const stderr = result.stderr.toString().trim()
throw new Error(`Rebase --continue failed: ${stderr || "(no output)"}`)
}
/** Abort an in-progress rebase. */