affaan-m/ECC · error

Invalid format: . Use text or json.

Error message

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

What it means

parseArgs in scripts/preview-pack-smoke.js validates the parsed format value against the allowlist ['text','json'] and throws this error otherwise. The script only supports these two output formats, so any other --format value is rejected before execution proceeds.

Solutions

  1. Use --format text or --format json exactly
  2. Check for case mismatches — values are lowercase
  3. Remove the --format flag to use the default
  4. Don't reuse flags from other audit scripts that support more formats

Example fix

// before
node scripts/preview-pack-smoke.js --format markdown
// after
node scripts/preview-pack-smoke.js --format json
Defensive patterns

Strategy: validation

Validate before calling

function validateFormat(format) {
  return ['text', 'json'].includes(format);
}
if (typeof format === 'string' && !validateFormat(format.toLowerCase())) {
  throw new Error(`--format must be text or json, got: ${format}`);
}

Type guard

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

Try / catch

try {
  await main(process.argv);
} catch (e) {
  if (e.message.startsWith('Invalid format:')) {
    console.error(`${e.message} (case-sensitive, lowercase)`);
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Passing `--format markdown`, `--format yaml`, or any value other than text or json; passing a value read from an unset env/variable yielding an empty or wrong string.

Common situations: Copy-pasting a --format value from platform-audit.js (which supports markdown) into this smoke script; scripting that interpolates an empty FORMAT variable; case mismatches like `--format JSON`.

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/976178d418bf5ae5. Report an issue: GitHub.

Appendix: source

Thrown at scripts/preview-pack-smoke.js:144

      continue;
    }

    if (arg === '--root') {
      parsed.root = path.resolve(readArgValue(args, index, arg));
      index += 1;
      continue;
    }

    if (arg.startsWith('--root=')) {
      parsed.root = path.resolve(arg.slice('--root='.length));
      continue;
    }

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

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

  return parsed;
}

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

function fileExists(rootDir, relativePath) {
  return fs.existsSync(path.join(rootDir, relativePath));
}

function safeParseJson(text) {

View on GitHub (pinned to 8321021c54)