eyaltoledano/claude-task-master · error
projectRoot is required for isOnDefaultBranch
Error message
projectRoot is required for isOnDefaultBranch
What it means
isOnDefaultBranch compares the current branch with the default branch, running both lookups inside projectRoot. An empty projectRoot makes that comparison impossible, so the guard throws this error before git commands execute. It is a fail-fast argument check.
Source
Thrown at packages/tm-core/src/common/utils/git-utils.ts:265
for (const defaultName of commonDefaults) {
if (
branches.includes(defaultName) ||
remoteBranches.includes(defaultName)
) {
return defaultName;
}
}
return null;
}
}
/**
* Check if we're currently on the default branch
*/
export async function isOnDefaultBranch(projectRoot: string): Promise<boolean> {
if (!projectRoot) {
throw new Error('projectRoot is required for isOnDefaultBranch');
}
try {
const [currentBranch, defaultBranch] = await Promise.all([
getCurrentBranch(projectRoot),
getDefaultBranch(projectRoot)
]);
return (
currentBranch !== null &&
defaultBranch !== null &&
currentBranch === defaultBranch
);
} catch (error) {
return false;
}
}
/**View on GitHub (pinned to c0c98d367c)
Solutions
- Pass a valid non-empty repository path to the function
- Fall back to process.cwd() when the configured root is missing
- Fix upstream projectRoot resolution/config loading
- Wrap the call in a guard that returns false (or skips the check) when root is unknown
Example fix
// before const onDefault = await isOnDefaultBranch(projectRoot); // '' // after const onDefault = projectRoot ? await isOnDefaultBranch(projectRoot) : false;
Defensive patterns
Strategy: validation
Validate before calling
if (!projectRoot || typeof projectRoot !== 'string') {
throw new Error('isOnDefaultBranch requires a non-empty projectRoot');
}
// safe pre-check of both underlying values:
const [cur, def] = await Promise.all([getCurrentBranch(projectRoot), getDefaultBranch(projectRoot)]);
const onDefault = cur !== null && def !== null && cur === def; Type guard
function isRoot(v: unknown): v is string {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
const onDefault = await isOnDefaultBranch(projectRoot);
} catch (err) {
if (err instanceof Error && err.message.includes('isOnDefaultBranch')) {
console.error('projectRoot missing; skipping default-branch safety check.');
return false; // treat as NOT safe rather than crashing
}
throw err;
} Prevention
- Treat the check as a safety gate: when root is unknown, assume not-on-default and skip risky writes
- Resolve and assert projectRoot before branch-safety logic
- Centralize root resolution so helpers never receive empty strings
- In CI, echo the workspace path before git-dependent steps to catch empty values early
When it happens
Trigger: Calling isOnDefaultBranch(undefined) or '' — typically an unset project root from config; also via Promise.all paths when the supplied root is empty string.
Common situations: Scripts checking 'safe to commit on main?' executed outside a configured project; pipelines where the workspace variable is empty; tests passing no fixture path.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- projectRoot is required for isGitRepository
- projectRoot is required for getCurrentBranch
- projectRoot is required for getLocalBranches
- projectRoot is required for getRemoteBranches
- projectRoot is required for getGitHubRepoInfo
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/c40659bcddf3de93.
Report an issue: GitHub.