CherryHQ/cherry-studio · error · Error

Unknown flag: ${flag}

Error message

Unknown flag: ${flag}

What it means

Thrown by scripts/capture-image-response.ts when the argument parser encounters a flag token it does not recognize. The switch statement handles only --url, --body, --method, --out, and --header; any other token starting with the flag pattern (or any token in flag position) hits the default case and throws.

Source

Thrown at scripts/capture-image-response.ts:56

        args.url = value
        break
      case '--body':
        args.body = value
        break
      case '--method':
        args.method = value.toUpperCase()
        break
      case '--out':
        args.out = value
        break
      case '--header': {
        const idx = value.indexOf(':')
        if (idx === -1) throw new Error(`Invalid --header (expected "Name: value"): ${value}`)
        args.headers[value.slice(0, idx).trim()] = value.slice(idx + 1).trim()
        break
      }
      default:
        throw new Error(`Unknown flag: ${flag}`)
    }
  }
  return args
}

async function main() {
  const args = parseArgs(process.argv.slice(2))
  if (!args.url) throw new Error('--url is required')

  const method = args.method ?? (args.body ? 'POST' : 'GET')
  const headers: Record<string, string> = { Accept: 'application/json', ...args.headers }
  if (args.body && !Object.keys(headers).some((h) => h.toLowerCase() === 'content-type')) {
    headers['Content-Type'] = 'application/json'
  }

  // Show the request WITHOUT auth values.
  const safeHeaders = Object.fromEntries(
    Object.entries(headers).map(([k, v]) => [k, /authorization|api-key|x-api-key|token/i.test(k) ? '<redacted>' : v])

View on GitHub (pinned to 726446b54c)

Solutions

  1. Use only the supported flags: --url (required), --body, --method, --out, --header (repeatable).
  2. Check spelling and case — flags are lowercase and exact (--url, not --URL or --Url).
  3. Use --out (not --output) and --method (not -X) — this script does not implement cURL shorthands.
  4. Re-read the usage comment at the top of scripts/capture-image-response.ts for the canonical invocation.

Example fix

# before
npx tsx scripts/capture-image-response.ts --URL 'https://...' --output resp.json

# after
npx tsx scripts/capture-image-response.ts --url 'https://...' --out resp.json
Defensive patterns

Strategy: validation

Validate before calling

const KNOWN_FLAGS = new Set(['--url', '--body', '--method', '--out', '--header'])
for (const tok of argv.filter((t) => t.startsWith('--'))) {
  if (!KNOWN_FLAGS.has(tok)) throw new Error(`Unknown flag: ${tok}`)
}

Type guard

const KNOWN = new Set(['--url','--body','--method','--out','--header'])
const isKnownFlag = (f: string): boolean => KNOWN.has(f)

Prevention

When it happens

Trigger: Passing a typo'd or unsupported flag such as --URL (wrong case), --ur1, --auth, --api-key, -H, or --output (the script uses --out). Any flag not in the supported set triggers this.

Common situations: Case-sensitivity mistake (--URL vs --url); using a cURL-style shorthand (-H, -X) the script does not accept; guessing a flag name from another tool; copy-pasting flags from documentation for a different script.

Related errors


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/48bd3b34d860cf87. Report an issue: GitHub.