{"record":{"id":"8677a2df05dbacb1","repo":"paperclipai/paperclip","slug":"error-instanceof-error-error-message-string","errorCode":null,"errorMessage":"${error instanceof Error ? error.message : String(error)}\\n${stderr}","messagePattern":"\\$\\{error instanceof Error \\? error\\.message : String\\(error\\)\\}\\\\n\\$\\{stderr\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/install.ts","lineNumber":51,"sourceCode":"  args: string[],\n  options?: Parameters<typeof execFileAsync>[2],\n) => Promise<{ stdout: string; stderr: string }>;\n\ntype ReleasePackageEntry = { dir: string; name: string };\n\nexport async function runCommandWithDiagnostics(\n  file: string,\n  args: string[],\n  options?: Parameters<typeof execFileAsync>[2],\n): Promise<{ stdout: string; stderr: string }> {\n  try {\n    return await execFileAsync(file, args, { ...options, encoding: \"utf8\" });\n  } catch (error) {\n    const stderr = error && typeof error === \"object\" && \"stderr\" in error && typeof error.stderr === \"string\"\n      ? error.stderr.trim()\n      : \"\";\n    if (!stderr || (error instanceof Error && error.message.includes(stderr))) throw error;\n    throw new Error(`${error instanceof Error ? error.message : String(error)}\\n${stderr}`, { cause: error });\n  }\n}\n\nexport function resolveGitInstallWorkspacePackages(checkoutPath: string): ReleasePackageEntry[] {\n  const manifestPath = path.join(checkoutPath, \"scripts\", \"release-package-manifest.json\");\n  const manifest = JSON.parse(fs.readFileSync(manifestPath, \"utf8\")) as ReleasePackageEntry[];\n  const packageByName = new Map(manifest.map((entry) => [entry.name, entry]));\n  const visiting = new Set<string>();\n  const visited = new Set<string>();\n  const ordered: ReleasePackageEntry[] = [];\n\n  const visit = (packageName: string): void => {\n    if (visited.has(packageName)) return;\n    if (visiting.has(packageName)) throw new Error(`Circular workspace dependency while staging ${packageName}.`);\n    const entry = packageByName.get(packageName);\n    if (!entry) throw new Error(`Git install cannot stage workspace dependency ${packageName}; it is missing from scripts/release-package-manifest.json.`);\n    visiting.add(packageName);\n    const packageJson = JSON.parse(fs.readFileSync(path.join(checkoutPath, entry.dir, \"package.json\"), \"utf8\")) as Record<string, unknown>;","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/install.ts#L33-L69","documentation":"Thrown by runCommandWithDiagnostics (install.ts:51) to enrich a failed execFile error with its stderr. The wrapper rethrows the original error if stderr is empty or already embedded in the message; otherwise it creates a new Error concatenating message + stderr and chains the original via `cause`.","triggerScenarios":"Any child process spawned by the installer (npm, git, node) exits non-zero and produces stderr that is not already part of the error message — e.g. npm install failures, git checkout errors, or shim write failures.","commonSituations":"npm registry/lockfile errors, git network failures during a --ref install, permission errors writing the managed shim, or missing system dependencies.","solutions":["Read both layers: the top line (npm/git message) and the appended stderr block.","Address the underlying tool failure (fix lockfile, fix permissions, retry network).","Re-run with the same command after fixing root cause; do not retry unchanged.","Inspect error.cause for the original execFile error if more detail is needed."],"exampleFix":"// before: catch only the surfaced message\ntry { await run(...) } catch (e) { console.log(e.message) }\n// after: also inspect cause and stderr\ntry { await run(...) } catch (e) { console.log(e.message, e.cause) }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function hasExecFileStderr(err: unknown): err is Error & { stderr: string } {\n  return !!err && typeof err === \"object\" && \"stderr\" in err && typeof (err as any).stderr === \"string\";\n}","tryCatchPattern":"try {\n  return await runCommandWithDiagnostics(file, args, options);\n} catch (err) {\n  const detail = err instanceof Error ? err.message : String(err);\n  const cause = (err as Error & { cause?: unknown }).cause;\n  console.error('Command failed:', detail, '\\ncause:', cause);\n  throw err;\n}","preventionTips":["Inspect both message lines and error.cause when diagnosing installer failures.","Fix the root cause (lockfile, permissions, network) before re-running.","Run the failing child command directly to reproduce its stderr in isolation."],"tags":["cli","install","child-process","diagnostics","error-chaining"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}