{"record":{"id":"01ffd729710647bd","repo":"JuliusBrussee/caveman","slug":"operation-failed-detail","errorCode":null,"errorMessage":"${operation} failed: ${detail}","messagePattern":"(.+?) failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"agents/check-profile-scope.mjs","lineNumber":33,"sourceCode":"]);\nconst SCHEMA_SUPPORT_PATHS = new Set([\n  SCHEMA_PATH,\n  \"agents/compile.mjs\",\n  \"agents/check-profile-scope.mjs\",\n  \"packages/cli/tests/agent-registry.runtime.mjs\",\n  \"tests/installer/agent-registry-compile.test.mjs\",\n  \"tests/installer/agent-registry-scope.test.mjs\",\n  ...GENERATED_PATHS,\n]);\n\nfunction runGit(cwd, args, encoding = \"utf8\") {\n  return spawnSync(\"git\", args, { cwd, encoding, maxBuffer: 8 * 1024 * 1024 });\n}\n\nfunction requireGit(result, operation) {\n  if (!result.error && result.status === 0) return result.stdout;\n  const detail = result.stderr?.toString().trim() || result.error?.message || `exit ${result.status}`;\n  throw new Error(`${operation} failed: ${detail}`);\n}\n\nfunction isConcreteProfile(path) {\n  return path !== SCHEMA_PATH && /^agents\\/profiles\\/[a-z0-9][a-z0-9-]*\\.json$/.test(path);\n}\n\nfunction isAllowedConcreteProfileCommitPath(path) {\n  return isConcreteProfile(path) || GENERATED_PATHS.has(path);\n}\n\nexport function checkProfileScope({ base, head, cwd = process.cwd() }) {\n  if (!REVISION_RE.test(base) || !REVISION_RE.test(head)) {\n    throw new Error(\"base and head must be full Git object IDs\");\n  }\n\n  const baseRegistry = runGit(cwd, [\"cat-file\", \"-e\", `${base}:agents/agents.json`]);\n  if (baseRegistry.error || baseRegistry.status !== 0) {\n    return { ok: true, skipped: true, message: \"profile registry absent at base (initial import); skipping lane-scope gate\" };","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/agents/check-profile-scope.mjs#L15-L51","documentation":"check-profile-scope's requireGit helper wraps every git invocation; if the git process errors, exits non-zero, or cannot be spawned, it throws Error(`${operation} failed: ${detail}`) embedding git's stderr (or the spawn error). It is a generic wrapper meaning 'a git subcommand this script ran did not succeed', not a domain error — the real cause is always in the detail string.","triggerScenarios":"git not installed or not on PATH (spawn error), running the script outside a git repository or wrong cwd, a bad revision passed to cat-file/diff, or any git command exiting non-zero (e.g. corrupted repo, permission issues).","commonSituations":"CI container without git, running the profile-scope check before repo initialization, shallow clones missing the base commit, or a typo'd base/head ref.","solutions":["Read the detail suffix of the message — it contains git's stderr; fix that underlying cause first","Install git / ensure it is on PATH in the execution environment","Run the script from inside the repository (or pass the correct cwd option)","Fetch the missing base revision if a shallow clone lacks it (git fetch origin <base>)","Run the failing git command manually with the same args to reproduce"],"exampleFix":"// before: run in non-repo dir\ncheckProfileScope({ base, head })\n// after\ncheckProfileScope({ base, head, cwd: '/path/to/repo' })","handlingStrategy":"try-catch","validationCode":"import { execFileSync } from 'node:child_process';\nfunction gitAvailable(cwd) {\n  try { execFileSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd, stdio: 'pipe' }); return true; }\n  catch { return false; }\n}\nif (!gitAvailable(cwd)) throw new Error(`not a git repo / git missing at ${cwd}`);","typeGuard":null,"tryCatchPattern":"try { checkProfileScope({ base, head, cwd }); } catch (e) {\n  if (/failed:/.test(e.message)) {\n    console.error('git invocation failed:', e.message); // detail carries git stderr\n    process.exitCode = 1;\n  } else throw e;\n}","preventionTips":["Run the check from inside the repository or always pass cwd explicitly","Ensure git is installed in CI images","Fetch base revisions in shallow clones before running the gate","Read the message detail — it contains the actual git stderr and the real cause"],"tags":["git","cli","subprocess"],"backgroundTag":"git-command-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}