style(runtime-fallback): add explicit optional chain on .replace per review

Addresses cubic-dev-ai P1 finding on #4113 (#4113 review).

The original chain `extractErrorName(error)?.toLowerCase().replace(...)`
is semantically safe — JavaScript optional chaining short-circuits the
ENTIRE access chain when the head returns null/undefined, so when
`extractErrorName` returns undefined the whole expression evaluates to
undefined without ever reaching `.replace()`. Verified empirically via
`const x = undefined; x?.toLowerCase().replace(/_/g, "")` returns
undefined with no crash.

Applying the suggested defensive `?.` before `.replace` anyway, since
it is semantically a no-op and explicit chaining at each hop is easier
for static analyzers to reason about.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZeyuFu
2026-05-17 11:05:01 -04:00
parent b2f0d42394
commit a8ccffdd7c
@@ -109,7 +109,7 @@ export function classifyErrorType(error: unknown): string | undefined {
// Normalize by stripping underscores and dashes so snake_case / kebab-case
// provider error names (e.g. "insufficient_quota", "RESOURCE_EXHAUSTED")
// match the existing alphanumeric .includes() checks below.
const errorName = extractErrorName(error)?.toLowerCase().replace(/[_-]/g, "")
const errorName = extractErrorName(error)?.toLowerCase()?.replace(/[_-]/g, "")
if (
errorName?.includes("ailoadapikeyerror") ||