{"record":{"id":"a0240f589ac43ab5","repo":"jlcodes99/cockpit-tools","slug":"codex-localaccess-testunavailable","errorCode":"codex.localAccess.testUnavailable","errorMessage":"当前 API 服务地址不可用","messagePattern":"当前 API 服务地址不可用","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pages/useCodexAccountsLocalAccessController.tsx","lineNumber":1738,"sourceCode":"            ? t(\"codex.localAccess.enabledSuccess\", \"API 服务已启用\")\n            : t(\"codex.localAccess.disabledSuccess\", \"API 服务已停用\"),\n        });\n        return nextState;\n      } catch (error) {\n        console.error(\"Failed to toggle local access service:\", error);\n        throw new Error(String(error).replace(/^Error:\\s*/, \"\"));\n      } finally {\n        setLocalAccessSaving(false);\n      }\n    }, [localAccessCollection, requestLocalAccessRiskNotice, setMessage, t]);\n  \n    const handleActivateLocalAccess = useCallback(\n      async (options?: {\n        showSuccessMessage?: boolean;\n        instanceId?: string | null;\n      }) => {\n        if (!localAccessCollection) {\n          throw new Error(\n            t(\"codex.localAccess.testUnavailable\", \"当前 API 服务地址不可用\"),\n          );\n        }\n        if (!localAccessCollection.enabled) {\n          const confirmedEnableAndSwitch = await confirmDialog(\n            t(\n              \"codex.localAccess.enableBeforeActivateMessage\",\n              \"API 服务当前未启用，需要先启用服务。是否启用并切号？\",\n            ),\n            {\n              title: t(\n                \"codex.localAccess.enableBeforeActivateTitle\",\n                \"服务未启用\",\n              ),\n              kind: \"warning\",\n              okLabel: t(\n                \"codex.localAccess.enableAndActivateAction\",\n                \"启用并切号\",","sourceCodeStart":1720,"sourceCodeEnd":1756,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/pages/useCodexAccountsLocalAccessController.tsx#L1720-L1756","documentation":"Thrown by `handleActivateLocalAccess` when `localAccessCollection` is null/undefined — there is no local API service collection (address) available to activate, so the \"test/activate\" target is unavailable (code `codex.localAccess.testUnavailable`, message \"当前 API 服务地址不可用\").","triggerScenarios":"Invoking activate-local-access (from the accounts page or with an `instanceId`) before any local access collection has been created/enabled, or after the collection data failed to load, so `localAccessCollection` is falsy at the top of the handler.","commonSituations":"Clicking \"activate API service\" on a fresh install before configuring a service address; the collection fetch failed silently earlier; an instance ID references a collection that was deleted.","solutions":["Create/enable a local API service collection first so `localAccessCollection` is populated, then activate.","Reload the Codex accounts page to re-fetch the collection state.","If a specific `instanceId` was passed, verify that instance still exists and has a configured address.","Guard the UI button (disable it) when `localAccessCollection` is null instead of letting the call throw."],"exampleFix":"// before\nawait handleActivateLocalAccess();\n// after\nif (!localAccessCollection) {\n  setMessage({ text: t(\"codex.localAccess.testUnavailable\"), tone: \"warning\" });\n  return;\n}\nawait handleActivateLocalAccess();","handlingStrategy":"type-guard","validationCode":"if (!localAccessCollection || !localAccessCollection.enabled) {\n  disableActivateButton();\n}","typeGuard":"function canActivateLocalAccess(c: LocalAccessCollection | null | undefined): c is LocalAccessCollection {\n  return !!c && typeof c.enabled === \"boolean\";\n}","tryCatchPattern":"try {\n  await handleActivateLocalAccess();\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"当前 API 服务地址不可用\")) {\n    openApiServiceConfigDialog();\n  } else { throw err; }\n}","preventionTips":["Load the collection state before rendering activate controls.","Disable the activate button when no collection exists.","Validate instanceId references on navigation."],"tags":["codex","local-access","configuration","null-state"],"backgroundTag":"service-endpoint-unavailable","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"}