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.
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)
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: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- targetPath must be a non-empty string
- content must be a non-empty string
- storeTasksInGit must be a boolean
- Failed to fetch tasks from any tag. First error: ${failedTag
- ${authCheck.error}
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/67221c4be98d3372.
Report an issue: GitHub.