CherryHQ/cherry-studio · error · Error

Invalid --header (expected "Name: value"): ${value}

Error message

Invalid --header (expected "Name: value"): ${value}

What it means

Thrown by scripts/capture-image-response.ts when a --header value does not contain a colon (':') separator. Headers must be in 'Name: value' form so the parser can split on the first colon into header name and value. Without a colon the split is impossible, so the script rejects the input rather than guessing.

Source

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

    const flag = argv[i]
    const value = argv[++i]
    if (value === undefined) throw new Error(`Missing value for ${flag}`)
    switch (flag) {
      case '--url':
        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'

View on GitHub (pinned to 726446b54c)

Solutions

  1. Format every --header as "Name: value" with a colon, e.g. --header "Authorization: Bearer $KEY".
  2. For headers whose value contains a colon (e.g. URLs, timestamps), note the split uses the FIRST colon — that is fine for standard names like 'Content-Type'.
  3. Quote the entire header argument so the shell preserves the colon and spaces.
  4. Double-check each --header token in your command for a colon before running.

Example fix

# before
npx tsx scripts/capture-image-response.ts --header "Authorization Bearer $KEY"

# after
npx tsx scripts/capture-image-response.ts --header "Authorization: Bearer $KEY"
Defensive patterns

Strategy: validation

Validate before calling

// Validate header shape before building the command
const headerPattern = /^[^:]+\s*:\s*.+$/
if (!headerPattern.test(headerString)) {
  throw new Error(`Header must be 'Name: value', got: ${headerString}`)
}

Type guard

const isValidHeader = (h: string): boolean => h.indexOf(':') !== -1

Prevention

When it happens

Trigger: Passing --header "Authorization Bearer xxx" (space instead of colon), --header "Authorization" (value missing), or a header where the colon was stripped by shell interpolation. The check is value.indexOf(':') === -1.

Common situations: Typing a header from memory with a space instead of a colon; copy-pasting a header that used an equals sign (Authorization=Bearer ...); a shell variable expansion that swallowed the colon; using cURL-style '-H Name: value' but forgetting the colon.

Related errors


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