{"record":{"id":"9bad1c711561d38d","repo":"mastra-ai/mastra","slug":"failed-to-clone-repository-giterror-instanceof-9bad1c","errorCode":null,"errorMessage":"Failed to clone repository: ${gitError instanceof Error ? gitError.message : 'Unknown error'}","messagePattern":"Failed to clone repository: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/clone-template.ts","lineNumber":135,"sourceCode":"      if (branch) {\n        gitArgs.push('--branch', branch);\n      }\n      gitArgs.push(repoUrl, targetPath);\n\n      await execa('git', gitArgs, {\n        cwd: process.cwd(),\n        ...(signal ? { cancelSignal: signal } : {}),\n      });\n      signal?.throwIfAborted();\n\n      // Remove .git directory\n      const gitDir = path.join(targetPath, '.git');\n      if (await directoryExists(gitDir)) {\n        await fs.rm(gitDir, { recursive: true, force: true });\n      }\n    } catch (gitError) {\n      if (signal?.aborted) signal.throwIfAborted();\n      throw new Error(`Failed to clone repository: ${gitError instanceof Error ? gitError.message : 'Unknown error'}`);\n    }\n  }\n}\n\nasync function updatePackageJson(projectPath: string, projectName: string): Promise<void> {\n  const packageJsonPath = path.join(projectPath, 'package.json');\n\n  try {\n    const packageJsonContent = await fs.readFile(packageJsonPath, 'utf-8');\n    const packageJson = JSON.parse(packageJsonContent);\n\n    // Update the name field\n    packageJson.name = projectName;\n\n    // Write back the updated package.json\n    await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');\n  } catch (error) {\n    // It's okay if package.json doesn't exist or can't be updated","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/utils/clone-template.ts#L117-L153","documentation":"When the degit path fails, cloneRepositoryWithoutGit falls back to `git clone`; if that git invocation throws, the original error is discarded and rewrapped as 'Failed to clone repository: <git message>'. The catch also rethrows abort errors unchanged and cleans up the target dir before the fallback path.","triggerScenarios":"cloneTemplate -> cloneRepositoryWithoutGit fallback `git clone <githubUrl> <targetPath>` exits non-zero (any gitError), and signal is not aborted.","commonSituations":"No git installed or git not on PATH; no network access / corporate proxy blocking github.com; repo private (auth required) or removed; invalid branch name; SSH/HTTPS auth failures; SSL certificate issues.","solutions":["Read the wrapped git message (e.g. 'could not resolve host', 'Authentication failed') and fix the underlying cause — network, proxy, or credentials.","Verify git is installed and on PATH (git --version).","Confirm the template repository URL and branch exist and are publicly accessible (or configure a GitHub token/SSH key).","Retry after restoring connectivity; the target directory is cleaned before fallback, so a fresh run is safe."],"exampleFix":"// before (private repo, no auth)\n// Error: Failed to clone repository: Authentication failed for 'https://github.com/org/private-template.git/'\n\n// after\n$ git config --global credential.helper store\n$ gh auth login   # or use an SSH remote / PAT","handlingStrategy":"try-catch","validationCode":"import { execFile } from 'node:child_process';\nexecFile('git', ['--version'], (err) => { if (err) throw new Error('git is not installed or not on PATH'); });","typeGuard":"function isGitError(e: unknown): e is Error & { killed?: boolean } {\n  return e instanceof Error;\n}","tryCatchPattern":"try {\n  await cloneTemplate(opts);\n} catch (err) {\n  const msg = err instanceof Error ? err.message : String(err);\n  if (msg.startsWith('Failed to clone repository:')) {\n    console.error('git clone failed:', msg); // inspect underlying git reason\n  }\n  throw err;\n}","preventionTips":["Ensure git is installed and on PATH.","Configure GitHub credentials (gh auth login, SSH keys, or PAT) for private templates.","Check proxy/firewall allows github.com; test with `git ls-remote <url>` before scaffolding."],"tags":["git","network","cloning","scaffolding"],"backgroundTag":"git-clone-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}