affaan-m/ECC · error · Error

Invalid format: . Use text, json, or markdown.

Error message

Invalid format: ${parsed.format}. Use text, json, or markdown.

What it means

After argument parsing, parseArgs validates that the selected output format is one of the allowed enum values: text, json, or markdown. If --format (or a format shorthand) produced any other string, this error is thrown to prevent writing an unsupported output type.

Solutions

  1. Use exactly one of: text, json, markdown (lowercase).
  2. Prefer the shorthand flags --json or --markdown which set the format directly.
  3. Check wrapper/CI scripts for variables that may be empty or wrong, e.g. `--format "$FMT"`.
  4. To support a new format, add it to the allowed list and implement rendering in main().

Example fix

// before
node scripts/operator-readiness-dashboard.js --format html
// after
node scripts/operator-readiness-dashboard.js --format markdown
Defensive patterns

Strategy: validation

Validate before calling

const FORMATS = ['text','json','markdown'];
if (format !== undefined && !FORMATS.includes(format)) {
  throw new Error(`Invalid format: ${format}. Use text, json, or markdown.`);
}

Type guard

function isDashboardFormat(v) { return v === 'text' || v === 'json' || v === 'markdown'; }

Try / catch

try {
  const parsed = parseArgs(args);
} catch (err) {
  if (err.message.startsWith('Invalid format:')) {
    console.error(`${err.message} (accepted: text, json, markdown)`);
    process.exit(2);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling `node scripts/operator-readiness-dashboard.js --format xml`, `--format html`, `--format JSON` (case-sensitive), or leaving parsed.format corrupted to a non-enum default triggers the `!['text','json','markdown'].includes(parsed.format)` check.

Common situations: Typos in the format value; assuming case-insensitive matching ('JSON' fails); using a format from a different tool ('yaml', 'csv'); a wrapper script interpolating an empty or wrong value into --format.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/5261260156866f5e. Report an issue: GitHub.

Appendix: source

Thrown at scripts/operator-readiness-dashboard.js:218

      index += 1;
      continue;
    }

    if (arg.startsWith('--generated-at=')) {
      parsed.generatedAt = arg.slice('--generated-at='.length);
      continue;
    }

    if (arg === '--exit-code') {
      parsed.exitCode = true;
      continue;
    }

    throw new Error(`Unknown argument: ${arg}`);
  }

  if (!['text', 'json', 'markdown'].includes(parsed.format)) {
    throw new Error(`Invalid format: ${parsed.format}. Use text, json, or markdown.`);
  }

  if (parsed.writePath && parsed.format === 'text') {
    throw new Error('--write requires --json, --markdown, or --format json|markdown');
  }

  parsed.allowUntracked = parsed.allowUntracked.map(normalizeRelativePrefix).filter(Boolean);

  return parsed;
}

function readText(rootDir, relativePath) {
  try {
    return fs.readFileSync(path.join(rootDir, relativePath), 'utf8');
  } catch (_error) {
    return '';
  }
}

View on GitHub (pinned to 8321021c54)