{"record":{"id":"14c514ec3771ef73","repo":"paperclipai/paperclip","slug":"extractexecsyncerrormessage-error-string-err","errorCode":null,"errorMessage":"${extractExecSyncErrorMessage(error) ?? String(error)}","messagePattern":"\\$\\{extractExecSyncErrorMessage\\(error\\) \\?\\? String\\(error\\)\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/worktree.ts","lineNumber":1009,"sourceCode":"  }\n\n  mkdirSync(path.dirname(targetPath), { recursive: true });\n\n  const spinner = p.spinner();\n  spinner.start(`Creating git worktree for ${branchName}...`);\n  try {\n    execFileSync(\"git\", resolveGitWorktreeAddArgs({\n      branchName,\n      targetPath,\n      branchExists: localBranchExists(repoRoot, branchName),\n    }), {\n      cwd: repoRoot,\n      stdio: [\"ignore\", \"pipe\", \"pipe\"],\n    });\n    spinner.stop(`Created git worktree at ${targetPath}.`);\n  } catch (error) {\n    spinner.stop(pc.red(\"Failed to create git worktree.\"));\n    throw new Error(extractExecSyncErrorMessage(error) ?? String(error));\n  }\n\n  installDependenciesBestEffort(targetPath);\n\n  return {\n    rootPath: targetPath,\n    configPath: path.resolve(targetPath, \".paperclip\", \"config.json\"),\n    label: branchName,\n    branchName,\n    created: true,\n  };\n}\n\nfunction resolveSourceConnectionString(config: PaperclipConfig, envEntries: Record<string, string>, portOverride?: number): string {\n  if (config.database.mode === \"postgres\") {\n    const connectionString = nonEmpty(envEntries.DATABASE_URL) ?? nonEmpty(config.database.connectionString);\n    if (!connectionString) {\n      throw new Error(","sourceCodeStart":991,"sourceCodeEnd":1027,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/worktree.ts#L991-L1027","documentation":"Thrown when `git worktree add` (via resolveGitWorktreeAddArgs) fails during worktree creation. The message is git's own stderr/stdout extracted by extractExecSyncErrorMessage, so it carries the precise reason git refused (e.g. branch already checked out elsewhere, invalid path, lock file held).","triggerScenarios":"Trying to create a worktree for a branch that is already checked out in another worktree; target path inside an existing worktree; a .git/worktrees lock is held; insufficient disk space or permissions; the branch name resolves to an existing but unrelated ref.","commonSituations":"Branch already checked out in the primary worktree; concurrent worktree operations; stale git lockfiles after a crash; branch name colliding with a tag or remote ref.","solutions":["Read the embedded git error text to identify the specific failure (most messages name the cause).","If the branch is checked out elsewhere, use a different branch or detach the other worktree first.","Run `git worktree prune` to clear stale worktree metadata and retry.","Remove any stale .git/*.lock files and ensure the target path is writable."],"exampleFix":"# before\n# (error from git worktree add)\n# after\ngit worktree prune\ngit worktree list   # confirm no stale entry\npaperclipai worktree ...","handlingStrategy":"try-catch","validationCode":"function branchIsNotCheckedOutElsewhere(repoRoot: string, branch: string): boolean {\n  try {\n    const list = execFileSync('git', ['worktree', 'list', '--porcelain'], { cwd: repoRoot, encoding: 'utf8' });\n    return !list.split('\\n').some(l => l.startsWith('branch ') && l.endsWith(branch));\n  } catch { return true; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await createWorktree(...);\n} catch (e) {\n  const msg = (e as Error).message;\n  if (/already checked out|locked/i.test(msg)) { /* detach other worktree or pick new branch */ }\n  else throw e;\n}","preventionTips":["Run `git worktree prune` before creation.","Avoid checking out the same branch in multiple worktrees.","Clear stale .git/*.lock files after crashes."],"tags":["git","worktree","execsync","filesystem"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}