{"record":{"id":"8aa8e37da8ea6b2d","repo":"jlcodes99/cockpit-tools","slug":"failures-join","errorCode":null,"errorMessage":"failures.join(\"; \") || \"无法解析导入内容\"","messagePattern":"failures\\.join\\(\"; \"\\) \\|\\| \"无法解析导入内容\"","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pages/useCodexAccountsAccessController.tsx","lineNumber":2634,"sourceCode":"          page.setAddMessage(\n            t(\"common.shared.externalImport.statusImporting\", {\n              current,\n              total: payloads.length,\n              defaultValue: \"正在导入第 {{current}} / {{total}} 个账号\",\n            }),\n          );\n          try {\n            imported.push(\n              ...(await codexService.importCodexFromJson(payloads[index])),\n            );\n          } catch (error) {\n            failures.push(\n              `${current}: ${String(error).replace(/^Error:\\s*/, \"\")}`,\n            );\n          }\n        }\n        if (imported.length === 0) {\n          throw new Error(failures.join(\"; \") || \"无法解析导入内容\");\n        }\n        // 待授权账号若带 2FA 秘钥，同步写入本地 MFA 速查\n        for (const account of imported) {\n          const secret = account.two_factor_secret?.trim();\n          if (!secret) continue;\n          setSavedMfaRecords(\n            upsertSavedMfaRecord({\n              secret,\n              accountName: account.email,\n              remark: account.account_note,\n            }),\n          );\n        }\n        await fetchAccounts();\n        await assignCodexAccountsToTargetGroup(imported);\n        if (imported.length > 0) {\n          await emitAccountsChanged({\n            platformId: \"codex\",","sourceCodeStart":2616,"sourceCodeEnd":2652,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/pages/useCodexAccountsAccessController.tsx#L2616-L2652","documentation":"When importing Codex accounts, each record is parsed in a loop; per-record errors are collected into a failures array. If nothing was successfully imported (imported.length === 0), the controller throws an Error whose message is all failures joined with '; ', or the fallback Chinese text '无法解析导入内容' ('unable to parse imported content') when failures is somehow empty. The error is an aggregate report of why every record failed.","triggerScenarios":"Importing a file/payload where every account record fails parsing/validation (e.g. malformed JSON entries, missing required fields, duplicate ids rejected) so imported stays empty; the thrown message lists each '<source>: <underlying error>' pair.","commonSituations":"Importing an accounts export from another tool or older version with a different schema; uploading a hand-edited JSON/YAML with syntax or field-name mistakes; importing an empty file so no records parse and the fallback message is used.","solutions":["Read the joined failure list in the message: each 'source: reason' entry points at the exact offending record and cause.","Fix or remove the invalid records in the import file and re-import (correct field names, valid JSON, required fields like id/token present).","Validate the file before import (JSON.parse plus a schema check per record) and pre-filter unparseable entries.","If the file is empty or entirely unreadable, regenerate the export from the source tool before importing.","Import incrementally (one or two records) to isolate which record shape the importer rejects."],"exampleFix":"// before\n// import file record missing required field\n{ \"name\": \"acct1\" }\n// after\n{ \"id\": \"acct1\", \"name\": \"acct1\", \"token\": \"...\" }  // required fields present","handlingStrategy":"try-catch","validationCode":"const validateImport = (records: unknown[]) =>\n  records.map((r, i) => {\n    const ok =\n      typeof r === 'object' && r !== null && 'id' in r;\n    return ok ? null : `record ${i}: missing required fields`;\n  }).filter(Boolean);","typeGuard":"const isImportableAccount = (r: unknown): r is { id: string; [k: string]: unknown } =>\n  typeof r === 'object' && r !== null &&\n  typeof (r as { id?: unknown }).id === 'string' &&\n  (r as { id: string }).id.length > 0;","tryCatchPattern":"try {\n  await importAccounts(file);\n} catch (e) {\n  const msg = String(e).replace(/^Error:\\s*/, '');\n  if (msg.includes('无法解析导入内容') || msg.includes('; ')) {\n    // aggregate failure list — show per-record reasons\n    showImportReport(msg.split('; '));\n  } else throw e;\n}","preventionTips":["Parse and schema-check the import file before calling the import API","Pre-filter invalid records and import only valid ones instead of all-or-nothing","Import in small batches to isolate problematic records","Ensure the export schema version matches what the importer expects","Show a per-record preview/review step before committing the import"],"tags":["import","batch-parsing","aggregated-errors","codex-cli"],"backgroundTag":"import-parse-failed","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}