eyaltoledano/claude-task-master · error
targetPath must end with .gitignore
Error message
targetPath must end with .gitignore
What it means
validateInputs requires the target path to actually end with '.gitignore' so the module never writes template content to the wrong file. It throws when targetPath is a valid string but lacks the .gitignore suffix.
Solutions
- Point targetPath at the exact file: path.join(projectRoot, '.gitignore')
- Remove stray extensions from the path string
- If managing a different ignore file, copy its contents rather than routing it through this API
Example fix
// before
manageGitignoreFile('myrepo/.gitignore.bak', content, true);
// after
manageGitignoreFile('myrepo/.gitignore', content, true); Defensive patterns
Strategy: validation
Validate before calling
if (typeof targetPath !== 'string' || !targetPath.endsWith('.gitignore')) {
throw new TypeError(`targetPath must end with .gitignore, got: ${targetPath}`);
} Type guard
const isGitignoreFile = (v) => typeof v === 'string' && v.endsWith('.gitignore'); Try / catch
try {
manageGitignoreFile(targetPath, content, storeTasksInGit);
} catch (err) {
if (err.message === 'targetPath must end with .gitignore') {
manageGitignoreFile(path.join(path.dirname(targetPath), '.gitignore'), content, storeTasksInGit);
} else throw err;
} Prevention
- Always construct the path as path.join(root, '.gitignore') instead of hand-writing it
- Check the suffix with endsWith('.gitignore') before calling
- Do not pass directories or backup/variant filenames to this API
When it happens
Trigger: Calling manageGitignoreFile with paths like 'path/to/.gitignore.txt', 'gitignore', a directory path 'repo/', or a file such as '.gitignore_global' — anything whose endsWith('.gitignore') check fails.
Common situations: Passing the project root or a directory instead of the file path; typos in the filename; using an alternate ignore file name that the validator does not accept; concatenating paths incorrectly so the suffix is lost.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- content must be a non-empty string
- storeTasksInGit must be a boolean
- targetPath must be a non-empty string
- ${authCheck.error}
- Either existingTaskId or newSubtaskData must be provided
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/67221c4be98d3372.
Report an issue: GitHub.
Appendix: source
Thrown at src/utils/manage-gitignore.js:153
lines.push('');
}
}
}
/**
* Validates input parameters
* @param {string} targetPath - Path to .gitignore file
* @param {string} content - Template content
* @param {boolean} storeTasksInGit - Storage preference
* @throws {Error} If validation fails
*/
function validateInputs(targetPath, content, storeTasksInGit) {
if (!targetPath || typeof targetPath !== 'string') {
throw new Error('targetPath must be a non-empty string');
}
if (!targetPath.endsWith('.gitignore')) {
throw new Error('targetPath must end with .gitignore');
}
if (!content || typeof content !== 'string') {
throw new Error('content must be a non-empty string');
}
if (typeof storeTasksInGit !== 'boolean') {
throw new Error('storeTasksInGit must be a boolean');
}
}
/**
* Creates a new .gitignore file from template
* @param {string} targetPath - Path to create file at
* @param {string[]} templateLines - Adjusted template lines
* @param {function} log - Logging function
*/
function createNewGitignoreFile(targetPath, templateLines, log) {View on GitHub (pinned to c0c98d367c)