{"record":{"id":"82d1519dd911df2b","repo":"midudev/autoskills","slug":"label-failed-result-stderr-trim-unknown-error","errorCode":null,"errorMessage":"${label} failed: ${result.stderr.trim() || \"unknown error\"}","messagePattern":"(.+?) failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/autoskills/scripts/sync-skills.mjs","lineNumber":333,"sourceCode":"  const r = spawnSync(\"tar\", [\"-xzf\", tarFile, \"-C\", destDir], {\n    stdio: FLAGS.verbose ? \"inherit\" : \"pipe\",\n  });\n  if (r.status !== 0) {\n    throw new Error(`tar extract failed (status ${r.status})`);\n  }\n  const entries = readdirSync(destDir);\n  const root = entries.find((e) => statSync(join(destDir, e)).isDirectory());\n  if (!root) throw new Error(`Empty tarball in ${destDir}`);\n  return join(destDir, root);\n}\n\nfunction runGit(args, label) {\n  const result = spawnSync(\"git\", args, {\n    encoding: \"utf-8\",\n    stdio: [\"ignore\", \"pipe\", \"pipe\"],\n  });\n  if (result.status !== 0) {\n    throw new Error(`${label} failed: ${result.stderr.trim() || \"unknown error\"}`);\n  }\n  return result.stdout;\n}\n\nfunction materializeSkillsFromSparseClone(repo, branch, skillNames, destRoot) {\n  const repoDir = join(destRoot, \"repo\");\n  runGit(\n    [\n      \"clone\",\n      \"--depth\",\n      \"1\",\n      \"--filter=blob:none\",\n      \"--sparse\",\n      \"--branch\",\n      branch,\n      `https://github.com/${repo}.git`,\n      repoDir,\n    ],","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/midudev/autoskills/blob/0ec725320d2137253ab2e68e7ba8a072148e741a/packages/autoskills/scripts/sync-skills.mjs#L315-L351","documentation":"runGit is a generic wrapper that runs a git command via spawnSync, capturing stdout/stderr, and throws `${label} failed: <stderr>` when git exits non-zero. It backs operations like sparse clones and checkouts during skill materialization; the label tells you which git step died.","triggerScenarios":"Any runGit(...) call where the spawned git exits with status !== 0 — e.g. `git clone --depth 1 --filter` fails on network/auth, `git sparse-checkout set` unsupported by old git, checkout of a nonexistent branch.","commonSituations":"Old local git (<2.25) lacking sparse-checkout support; cloning a private repo without credentials; network interruption mid-clone; branch name in config doesn't exist on the remote.","solutions":["Re-run with --verbose if available, or run the same git command manually to see full stderr","Upgrade git to a recent version (sparse-checkout needs >=2.25)","Check credentials for the remote (GITHUB_TOKEN / git credential helper) if the failure is auth-related","Verify the configured branch exists on the remote"],"exampleFix":"// before\n$ git --version # git version 2.17 — no sparse-checkout\n// after\n$ brew install git # or apt upgrade git → >=2.25","handlingStrategy":"try-catch","validationCode":"// verify git version supports the features used (sparse-checkout needs >=2.25)\nimport { execSync } from \"node:child_process\";\nconst v = execSync(\"git --version\", { encoding: \"utf8\" }).match(/(\\d+)\\.(\\d+)/);\nif (Number(v[1]) < 2 || (Number(v[1]) === 2 && Number(v[2]) < 25)) {\n  throw new Error(\"git >= 2.25 required for sparse-checkout\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await syncSkills(opts);\n} catch (err) {\n  if (err.message.includes(\"failed:\")) {\n    console.error(`git step failed: ${err.message}`);\n    // classify: auth → fix credentials; network → retry; old git → upgrade\n  } else throw err;\n}","preventionTips":["Keep local git >= 2.25 for sparse-checkout support","Configure credential helpers / GITHUB_TOKEN before cloning","Test the exact git commands manually once before automating them","Verify branch names exist on the remote"],"tags":["git","subprocess","clone"],"backgroundTag":"git-command-failed","analyzedSha":"0ec725320d2137253ab2e68e7ba8a072148e741a","analyzedAt":"2026-09-15T14:12:31.090Z","contentChangedAt":"2026-09-15T14:12:31.090Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}