{"record":{"id":"f146d065e8af2bb1","repo":"eyaltoledano/claude-task-master","slug":"repository-validation-failed-errormessage","errorCode":null,"errorMessage":"Repository validation failed: ${errorMessage}","messagePattern":"Repository validation failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/modules/git/adapters/git-adapter.ts","lineNumber":173,"sourceCode":"\t *\n\t * @example\n\t * await git.validateRepository();\n\t * console.log('Repository is valid');\n\t */\n\tasync validateRepository(): Promise<void> {\n\t\t// Check if it's a git repository\n\t\tconst isRepo = await this.isGitRepository();\n\t\tif (!isRepo) {\n\t\t\tthrow new Error(`not a git repository: ${this.projectPath}`);\n\t\t}\n\n\t\t// Try to get repository status to verify it's not corrupted\n\t\ttry {\n\t\t\tawait this.git.status();\n\t\t} catch (error) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`Repository validation failed: ${errorMessage}`);\n\t\t}\n\t}\n\n\t/**\n\t * Ensures we're in a valid git repository before performing operations.\n\t * Convenience method that throws descriptive errors.\n\t *\n\t * @returns {Promise<void>}\n\t * @throws {Error} If not in a valid git repository\n\t *\n\t * @example\n\t * await git.ensureGitRepository();\n\t * // Safe to perform git operations after this\n\t */\n\tasync ensureGitRepository(): Promise<void> {\n\t\tconst isRepo = await this.isGitRepository();\n\t\tif (!isRepo) {\n\t\t\tthrow new Error(","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/modules/git/adapters/git-adapter.ts#L155-L191","documentation":"validateRepository() in GitAdapter wraps any failure from simple-git's status() call into `Repository validation failed: <message>`. It is thrown only after confirming the path IS a git repo, so this means the repo exists but its metadata is unreadable or corrupted (or the git binary failed). The library throws it so callers get a consistent, prefixed error during pre-flight integrity checks.","triggerScenarios":"Calling gitAdapter.validateRepository() when simple-git's this.git.status() throws — e.g. corrupted .git directory, missing HEAD or objects, permission denied on .git, broken index.lock, or git binary errors despite a repo being detected by isGitRepository().","commonSituations":"Interrupted git operations leaving a stale .git/index.lock; disk corruption or partially cloned repos; .git owned by another user (WSL/Windows permission issues); a bare or invalid checkout where status fails; git version incompatibilities.","solutions":["Read the wrapped inner message after 'Repository validation failed: ' — it names the actual git failure.","Remove a stale lock file if present: rm .git/index.lock (only when no git process is running).","Run `git status` manually in the directory to reproduce and confirm it's a repo-level problem, not your code.","Fix permissions on .git (chown/chmod) if the error is EACCES/permission denied.","If the repo is corrupted, re-clone or run `git fsck` / restore .git from backup."],"exampleFix":"// before\nawait git.validateRepository(); // throws opaque wrapper\n// after\ntry {\n  await git.validateRepository();\n} catch (e) {\n  console.error('repo invalid:', (e as Error).message.replace('Repository validation failed: ', ''));\n}","handlingStrategy":"try-catch","validationCode":"import { execFile } from 'child_process';\nexecFile('git', ['-C', projectPath, 'status', '--porcelain'], (err) => {\n  if (err) console.warn('repo status failed:', err.message);\n});","typeGuard":"function isRepoValidationError(e: unknown): e is Error & { message: string } {\n  return e instanceof Error && e.message.startsWith('Repository validation failed: ');\n}","tryCatchPattern":"try {\n  await git.validateRepository();\n} catch (e) {\n  if (isRepoValidationError(e)) {\n    const gitReason = e.message.replace('Repository validation failed: ', '');\n    // surface gitReason; check for index.lock / permission issues\n  }\n  throw e;\n}","preventionTips":["Run validateRepository() once at startup and fail fast with the unwrapped inner message.","Monitor for leftover .git/index.lock after crashed runs.","Keep the git binary installed and on PATH in CI images.","Avoid sharing .git across users/containers with mismatched file permissions."],"tags":["git","corrupted-repository","validation"],"backgroundTag":"git-repository-corrupted","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}