jlcodes99/cockpit-tools · error
message
Error message
message
What it means
The Codex API-service save handler wraps its async work in try/catch; on failure it stringifies the error, strips the leading 'Error:' prefix, stores it via setError, and rethrows new Error(message). The bare message 'message' in a trace indicates an error was caught and rethrown here — the actual cause is the inner operation (e.g. error 82) whose text got flattened into a string.
Source
Thrown at src/pages/CodexApiServicePage.tsx:2137
preferredAccountIds?: string[],
imageGenerationAccountPolicies?: Record<string, CodexLocalAccessImageGenerationPolicy>,
) => {
setBusy(true);
setError("");
setNotice("");
try {
await saveMembers(
accountIds,
restrictFreeAccounts,
backupAccountIds,
preferredAccountIds,
imageGenerationAccountPolicies,
);
setNotice(t("codex.localAccess.saveSuccess", "API 服务集合已更新"));
} catch (err) {
const message = String(err).replace(/^Error:\s*/, "");
setError(message);
throw new Error(message);
} finally {
setBusy(false);
}
};
const handleRecoverAccounts = async (accountIds: string[]) => {
if (busy || accountIds.length === 0) return;
setBusy(true);
setError("");
setNotice("");
try {
const next =
await codexLocalAccessService.recoverCodexLocalAccessAccounts(
accountIds,
);
setState(next);
setNotice(
t("codex.localAccess.accountPoolHealth.recoverSuccess", {View on GitHub (pinned to 1ed8b77992)
Solutions
- Inspect setError text / console for the original cause — the rethrown message is only a copy.
- Fix the underlying error (e.g. no eligible accounts, network failure) rather than the rethrow site.
- If the double-wrap complicates handling, log err before rethrowing or rethrow the original error object.
Example fix
// before
} catch (err) {
const message = String(err).replace(/^Error:\s*/, "");
setError(message);
throw new Error(message);
}
// after
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
setError(message);
throw err; // preserve original stack/cause
} Defensive patterns
Strategy: try-catch
Try / catch
try {
await saveLocalAccess();
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
setError(msg);
// do not rethrow a new Error; rethrow original to keep stack
} Prevention
- Rethrow the original error object instead of new Error(String(err)) to preserve stack traces.
- Use instanceof Error narrowing instead of String(err) to avoid 'Error: ' prefix surprises.
- Log the original error before rewrapping so the root cause is diagnosable.
When it happens
Trigger: Any rejection inside the handleSaveLocalAccess try block (network failure, eligibility error, backend rejection) reaches the catch at CodexApiServicePage.tsx:2137 and is rethrown as new Error(String(err).replace(/^Error:\s*/, '')).
Common situations: Saving the API-service set while an eligible-account error or request failure occurs; the rethrow propagates to an outer handler so the caller sees the re-wrapped message rather than the original stack.
Related errors
- messages.rawLineNoRefreshToken(item.lineNumber)
- messages.rawLineMultipleRefreshTokens(item.lineNumber)
- PROVIDER_NAME_REQUIRED
- PROVIDER_BASE_URL_INVALID
- codex.localAccess.noEligibleAccountsSelected
AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05).
Data as JSON: /api/errors/64ebdb74b92e8b04.
Report an issue: GitHub.