{"record":{"id":"bd9fd6f7a11f3567","repo":"jlcodes99/cockpit-tools","slug":"readbundlemessage-msg-readbundlemessage-messag","errorCode":null,"errorMessage":"readBundleMessage(msg) ?? readBundleMessage(message) ?? readBundleMessage(error) ?? messages.empty","messagePattern":"readBundleMessage\\(msg\\) \\?\\? readBundleMessage\\(message\\) \\?\\? readBundleMessage\\(error\\) \\?\\? messages\\.empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/hooks/useProviderAccountsPage.ts","lineNumber":391,"sourceCode":"    if (platformId === 'codex') {\n      try {\n        const rawRefreshTokenItems = parseCodexRawRefreshTokenItems(rawContent, messages);\n        if (rawRefreshTokenItems && rawRefreshTokenItems.length > 0) {\n          return rawRefreshTokenItems;\n        }\n      } catch (error) {\n        throw error;\n      }\n    }\n\n    if (lineDelimitedError) throw lineDelimitedError;\n    throw new Error(messages.invalidJson);\n  }\n\n  if (parsed && typeof parsed === 'object' && 'code' in parsed) {\n    const code = (parsed as { code?: unknown }).code;\n    if (code !== 200 && code !== '200') {\n      throw new Error(\n        readBundleMessage((parsed as { msg?: unknown }).msg) ??\n          readBundleMessage((parsed as { message?: unknown }).message) ??\n          readBundleMessage((parsed as { error?: unknown }).error) ??\n          messages.empty,\n      );\n    }\n  }\n\n  const root =\n    parsed && typeof parsed === 'object' && 'data' in parsed\n      ? (parsed as { data?: unknown }).data\n      : parsed;\n\n  if (typeof root === 'string') {\n    return resolveExternalImportBundleItems(root, platformId, messages);\n  }\n\n  if (Array.isArray(root)) {","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/hooks/useProviderAccountsPage.ts#L373-L409","documentation":"The imported JSON parsed to an API-style envelope containing a 'code' field that is not 200 (or \"200\"). The parser surfaces the API's own error message from msg/message/error; messages.empty is the fallback when none of those fields carry a usable string (line 391). This is the remote endpoint reporting failure, not a local syntax problem.","triggerScenarios":"Pasting a raw HTTP API response body whose envelope has code != 200 and no msg/message/error string field (or only empty strings).","commonSituations":"Copying an error response (401/404/500 body) instead of the success payload; API requires auth so it returned {code:401}; older API versions using different error field names; rate-limit or maintenance responses.","solutions":["Re-fetch the export from the API with valid authentication so code is 200","Read the actual HTTP status/headers instead of pasting the error body","If you control the endpoint, include a non-empty msg or message field so users see the real reason","Paste only the data payload rather than the whole error envelope"],"exampleFix":"// before\n{\"code\":401,\"msg\":\"\"}\n// after (successful export)\n{\"code\":200,\"data\":{\"items\":[{\"refresh_token\":\"rt_a\"}]}}","handlingStrategy":"try-catch","validationCode":"const bundle: unknown = JSON.parse(content);\nif (bundle && typeof bundle === 'object' && 'code' in bundle) {\n  const b = bundle as { code?: unknown; msg?: unknown; message?: unknown };\n  if (b.code !== 200 && b.code !== '200') {\n    throw new Error(`API error (code ${String(b.code)}): ${String(b.msg ?? b.message ?? 'unknown')}`);\n  }\n}","typeGuard":"const isSuccessfulEnvelope = (v: unknown): boolean =>\n  !!v && typeof v === 'object' && !Array.isArray(v) &&\n  ((v as { code?: unknown }).code === 200 || (v as { code?: unknown }).code === '200');","tryCatchPattern":"try {\n  items = resolveExternalImportBundleItems(content, platformId, messages);\n} catch (e) {\n  if (e instanceof Error && e.message !== messages.invalidJson && e.message !== messages.noItems) {\n    showRemoteApiError(e.message);\n  }\n}","preventionTips":["Only paste successful (code 200) API responses, not error bodies","Check HTTP status before exporting/pasting the response body","Ensure the export endpoint is authenticated and reachable","Include a descriptive msg field in custom endpoints so failures are legible"],"tags":["api","import","envelope","error-response"],"backgroundTag":"api-error-response","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"}