decolua/9router · error

Item is not an object

Error message

Item is not an object

What it means

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.

Source

Thrown at src/app/api/oauth/grok-cli/bulk-import/route.js:58

    accounts = null;
  }

  if (!Array.isArray(accounts) || accounts.length === 0) {
    return NextResponse.json(
      { error: "No accounts provided" },
      { status: 400 }
    );
  }

  const results = [];
  let success = 0;
  let failed = 0;

  for (let i = 0; i < accounts.length; i++) {
    const raw = accounts[i];
    try {
      if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
        throw new Error("Item is not an object");
      }

      const accessToken = raw.access_token || raw.accessToken;
      const refreshToken = raw.refresh_token || raw.refreshToken || null;
      const idToken = raw.id_token || raw.idToken || null;
      let email = raw.email || null;

      if (!accessToken || typeof accessToken !== "string") {
        throw new Error("Missing access_token / accessToken");
      }

      if (!email) {
        email =
          decodeXaiIdTokenEmail(idToken) ||
          extractEmailFromAccessToken(accessToken) ||
          null;
      }

View on GitHub (pinned to 90b52e06ff)

Solutions

  1. Make each accounts[] element an object containing at least access_token (or accessToken).
  2. Strip nulls and non-object entries from the array.
  3. Wrap bare tokens: { access_token: token }.

Example fix

// before
{ "accounts": [null, "tok_123"] }
// after
{ "accounts": [{ "access_token": "tok_123" }] }
Defensive patterns

Strategy: type-guard

Validate before calling

const bad = accounts.findIndex(
  (a) => !a || typeof a !== "object" || Array.isArray(a)
);
if (bad !== -1) throw new Error(`accounts[${bad}] must be an object`);

Type guard

const isImportItem = (x) =>
  x !== null && typeof x === "object" && !Array.isArray(x);

Try / catch

try {
  await grokBulkImport(accounts);
} catch (e) {
  if (e.message === "Item is not an object") {
    accounts = accounts.filter(isImportItem);
  } else throw e;
}

Prevention

When it happens

Trigger: POSTing to /api/oauth/grok-cli/bulk-import with any accounts[] element that is null, a string, a number, or a nested array.

Common situations: Feeding a list of raw token strings, a malformed JSON export from grok-cli auth files, or hand-edited arrays with null placeholders.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of decolua/9router@90b52e06ff (2026-08-30). Data as JSON: /api/errors/31cb61e4d2a00156. Report an issue: GitHub.