eyaltoledano/claude-task-master · error
targetPath must be a non-empty string
Error message
targetPath must be a non-empty string
What it means
validateInputs in manage-gitignore requires targetPath to be a truthy non-empty string. It throws this error when the path to the target .gitignore file is missing or has the wrong type. This is the first of several sequential checks before the module touches the filesystem.
Source
Thrown at src/utils/manage-gitignore.js:149
function addSeparatorIfNeeded(lines) {
if (lines.some((line) => line.trim())) {
const lastLine = lines[lines.length - 1];
if (lastLine && lastLine.trim()) {
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 atView on GitHub (pinned to c0c98d367c)
Solutions
- Pass an explicit string path ending in .gitignore, e.g. manageGitignoreFile(path.join(projectRoot, '.gitignore'), content, true)
- Verify the caller resolves projectRoot correctly before building the path
- Use path.join/String() to normalize Path-like values into plain strings
Example fix
// before manageGitignoreFile(projectRoot, content, store); // wrong: directory, not file path // after manageGitignoreFile(path.join(projectRoot, '.gitignore'), content, store);
Defensive patterns
Strategy: type-guard
Validate before calling
function isGitignorePath(v) { return typeof v === 'string' && v.length > 0; }
if (!isGitignorePath(targetPath)) throw new TypeError(`targetPath must be a non-empty string, got ${typeof targetPath}`); Type guard
const isNonEmptyString = (v) => typeof v === 'string' && v.length > 0;
Try / catch
try {
manageGitignoreFile(targetPath, content, storeTasksInGit);
} catch (err) {
if (err.message.startsWith('targetPath must be a non-empty string')) {
targetPath = path.join(process.cwd(), '.gitignore');
manageGitignoreFile(targetPath, content, storeTasksInGit);
} else throw err;
} Prevention
- Build the path with path.join(projectRoot, '.gitignore') so it is always a string
- Never pass config objects where strings are expected
- Validate arguments once in your own wrapper before calling the API
When it happens
Trigger: Calling manageGitignoreFile (via validateInputs) with targetPath undefined/null, an empty string '', a number, or a non-string object (e.g. a URL or Path object).
Common situations: Programmatic API misuse where projectRoot was not joined with '.gitignore'; calling the helper before config load completed; passing an object {path: ...} instead of a plain string.
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 end with .gitignore
- 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/f5b5a4d8d7bc7653.
Report an issue: GitHub.