{"record":{"id":"cd63a22bd6f32024","repo":"Yeachan-Heo/oh-my-codex","slug":"invalid-input-json-error-instanceof-error-e-cd63a2","errorCode":null,"errorMessage":"Invalid --input JSON: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Invalid --input JSON: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/cli/team.ts","lineNumber":546,"sourceCode":"  let input: Record<string, unknown> = {};\n  let json = false;\n  for (let i = 1; i < args.length; i += 1) {\n    const token = args[i];\n    if (token === '--json') {\n      json = true;\n      continue;\n    }\n    if (token === '--input') {\n      const next = args[i + 1];\n      if (!next) throw new Error('Missing value after --input');\n      try {\n        const parsed = JSON.parse(next) as unknown;\n        if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n          throw new Error('input must be a JSON object');\n        }\n        input = parsed as Record<string, unknown>;\n      } catch (error) {\n        throw new Error(`Invalid --input JSON: ${error instanceof Error ? error.message : String(error)}`);\n      }\n      i += 1;\n      continue;\n    }\n    if (token.startsWith('--input=')) {\n      const raw = token.slice('--input='.length);\n      try {\n        const parsed = JSON.parse(raw) as unknown;\n        if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n          throw new Error('input must be a JSON object');\n        }\n        input = parsed as Record<string, unknown>;\n      } catch (error) {\n        throw new Error(`Invalid --input JSON: ${error instanceof Error ? error.message : String(error)}`);\n      }\n      continue;\n    }\n    throw new Error(`Unknown argument for \"omx team api\": ${token}`);","sourceCodeStart":528,"sourceCodeEnd":564,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/cli/team.ts#L528-L564","documentation":"Thrown by the catch in parseTeamApiArgs when the token after `--input` fails JSON.parse (syntax error). The original parser message is appended so you can see exactly where the JSON is malformed.","triggerScenarios":"`--input '{name:acme}'` (unquoted keys), trailing commas, unescaped quotes broken by shell quoting, or truncated JSON.","commonSituations":"Shell single/double-quote mangling of the JSON string, hand-typing JSON without quoting keys, or copy-paste truncation.","solutions":["Validate the payload with a JSON linter or `echo '<json>' | jq .` before running the command.","Use single quotes around the JSON in POSIX shells and avoid single quotes inside, or escape properly.","Prefer writing the JSON to a file and using shell substitution, or the --input= form, to reduce quoting issues."],"exampleFix":"# before\nomx team api create --input '{name:\"acme\"}'\n# after\nomx team api create --input '{\"name\":\"acme\"}'","handlingStrategy":"try-catch","validationCode":"try { JSON.parse(inputJson); } catch (e) {\n  console.error(`Payload is not valid JSON: ${e instanceof Error ? e.message : e}`);\n  process.exit(2);\n}","typeGuard":"function isParsableJson(s: string): boolean {\n  try { JSON.parse(s); return true; } catch { return false; }\n}","tryCatchPattern":"try { await teamApi(args); } catch (e) {\n  if (e instanceof Error && e.message.startsWith('Invalid --input JSON')) { /* surface parser detail, fix quoting */ }\n  else throw e;\n}","preventionTips":["Single-quote the JSON in POSIX shells; never let the shell re-parse inner double quotes.","Validate with `jq -c .` before passing."],"tags":["cli","json-parse","quoting"],"backgroundTag":"invalid-json-input","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}