eyaltoledano/claude-task-master · error

content must be a non-empty string

Error message

content must be a non-empty string

What it means

validateInputs requires content — the gitignore template text to write — to be a truthy non-empty string. It throws when content is missing, empty, or not a string, preventing the module from creating a blank or invalid .gitignore file.

Source

Thrown at src/utils/manage-gitignore.js:157

/**
 * 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) {
	try {
		fs.writeFileSync(targetPath, templateLines.join('\n') + '\n');
		if (typeof log === 'function') {
			log('success', `Created ${targetPath} with full template`);

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Pass the template string explicitly, e.g. the standard Task Master gitignore snippet
  2. Convert Buffers to strings: content = fs.readFileSync(tplPath, 'utf8')
  3. Fix template/asset loading so a valid string is always produced before calling

Example fix

// before
const content = fs.readFileSync(tplPath); // Buffer, may be rejected
manageGitignoreFile(p, content, true);
// after
const content = fs.readFileSync(tplPath, 'utf8');
manageGitignoreFile(p, content, true);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof content !== 'string' || content.length === 0) {
  content = DEFAULT_GITIGNORE_CONTENT; // supply a template before calling
}

Type guard

const isNonEmptyString = (v) => typeof v === 'string' && v.length > 0;

Try / catch

try {
  manageGitignoreFile(targetPath, content, storeTasksInGit);
} catch (err) {
  if (err.message.startsWith('content must be a non-empty string')) {
    manageGitignoreFile(targetPath, fs.readFileSync(templatePath, 'utf8'), storeTasksInGit);
  } else throw err;
}

Prevention

When it happens

Trigger: Calling manageGitignoreFile with content undefined/null, '' , a number, or a non-string value such as a Buffer or an options object.

Common situations: Template file failed to load (fs.readFileSync result not converted with toString, or the read threw and a default of undefined was used); asset resolution returned null; refactor passing an options bag where a string was expected.

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


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/0e29a8acf905ec28. Report an issue: GitHub.