{"record":{"id":"31cb61e4d2a00156","repo":"decolua/9router","slug":"item-is-not-an-object-31cb61","errorCode":null,"errorMessage":"Item is not an object","messagePattern":"Item is not an object","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/app/api/oauth/grok-cli/bulk-import/route.js","lineNumber":58,"sourceCode":"    accounts = null;\n  }\n\n  if (!Array.isArray(accounts) || accounts.length === 0) {\n    return NextResponse.json(\n      { error: \"No accounts provided\" },\n      { status: 400 }\n    );\n  }\n\n  const results = [];\n  let success = 0;\n  let failed = 0;\n\n  for (let i = 0; i < accounts.length; i++) {\n    const raw = accounts[i];\n    try {\n      if (!raw || typeof raw !== \"object\" || Array.isArray(raw)) {\n        throw new Error(\"Item is not an object\");\n      }\n\n      const accessToken = raw.access_token || raw.accessToken;\n      const refreshToken = raw.refresh_token || raw.refreshToken || null;\n      const idToken = raw.id_token || raw.idToken || null;\n      let email = raw.email || null;\n\n      if (!accessToken || typeof accessToken !== \"string\") {\n        throw new Error(\"Missing access_token / accessToken\");\n      }\n\n      if (!email) {\n        email =\n          decodeXaiIdTokenEmail(idToken) ||\n          extractEmailFromAccessToken(accessToken) ||\n          null;\n      }\n","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/app/api/oauth/grok-cli/bulk-import/route.js#L40-L76","documentation":"The grok-cli bulk-import route validates each element of accounts the same way as codex import: it must be a non-null, non-array object. Failures are caught per item and counted in the failed counter, so remaining items still import.","triggerScenarios":"POSTing to /api/oauth/grok-cli/bulk-import with any accounts[] element that is null, a string, a number, or a nested array.","commonSituations":"Feeding a list of raw token strings, a malformed JSON export from grok-cli auth files, or hand-edited arrays with null placeholders.","solutions":["Make each accounts[] element an object containing at least access_token (or accessToken).","Strip nulls and non-object entries from the array.","Wrap bare tokens: { access_token: token }."],"exampleFix":"// before\n{ \"accounts\": [null, \"tok_123\"] }\n// after\n{ \"accounts\": [{ \"access_token\": \"tok_123\" }] }","handlingStrategy":"type-guard","validationCode":"const bad = accounts.findIndex(\n  (a) => !a || typeof a !== \"object\" || Array.isArray(a)\n);\nif (bad !== -1) throw new Error(`accounts[${bad}] must be an object`);","typeGuard":"const isImportItem = (x) =>\n  x !== null && typeof x === \"object\" && !Array.isArray(x);","tryCatchPattern":"try {\n  await grokBulkImport(accounts);\n} catch (e) {\n  if (e.message === \"Item is not an object\") {\n    accounts = accounts.filter(isImportItem);\n  } else throw e;\n}","preventionTips":["Send objects with access_token fields, not bare token strings","Sanitize the import file (drop nulls/non-objects) before upload","Validate JSON array shape in the exporter tool"],"tags":["validation","bulk-import","grok"],"backgroundTag":"schema-validation-failed","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}