fix: prevent validation errors from being classified as network errors - #1270
awhite0030 wants to merge 1 commit into
Conversation
Root cause: Error classification in `isNetworkError` relies on simplistic `.includes()` checks (like `includes('connection')`), which causes standard validation errors (e.g. "validation failed for connection") to be misclassified as network errors.
Fix: Updated `isNetworkError` and `isValidationError` to use case-insensitive substring matching on `error.message`. Crucially, we now prevent an error from being flagged as a network error if it is already classified as a validation error (unless its name explicitly denotes it as a Fetch/Network error). Added regression tests to ensure standard error checks (like 'fetch failed' or 'invalid email') continue to function correctly.
Validation: Ran `pnpm run build`, `pnpm test:format`, `pnpm test:lint`, `pnpm test:types`, `pnpm test:knip`, and targeted `pnpm test:ava source/utils/error-formatter.spec.ts`. All passed.
Fixes Nano-Collective#1136
nc-review: needs work — 1 blocking, 1 important, 1 nit@awhite0030 — there is a blocking item below. The PR correctly fixes the misclassification of validation errors as network errors in source/utils/error-formatter.ts by short-circuiting isNetworkError when isValidationError matches (unless the error name is explicitly FetchError or NetworkError), and adds sensible regression tests. The changeset is present and well-formed. However, this is a near-verbatim duplicate of open PR #1155 ('fix(utils): classify validation errors strictly over network substring heuristics') which addresses the same linked bug; one should be closed in favour of the other.
🔴 blocking · Open PR #1155 ( 🟠 important · The new guard correctly handles the reported case ('validation failed for connection' must not match network), but ⚪ nit · The 'retains original capability to recognize timeout exceeded' test sets 🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with |
|
Can you take a look at the bot comments please @awhite0030 :) |
|
Hi @awhite0030, thanks for this PR! It looks like a maintainer has left feedback Whenever you get a chance, could you take a look at the open comments? |
52e9c78 to
ec8ee46
Compare
Description
Brief description of what this PR does
Type of Change
Changeset
pnpm changeset) describing this change for the changelogDocs-only or internal chores need no changeset (or run
pnpm changeset --emptyto note that intentionally).Testing
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)Manual Testing
Checklist
Root cause: Error classification in
isNetworkErrorrelies on simplistic.includes()checks (likeincludes('connection')), which causes standard validation errors (e.g. "validation failed for connection") to be misclassified as network errors.Fix: Updated
isNetworkErrorandisValidationErrorto use case-insensitive substring matching onerror.message. Crucially, we now prevent an error from being flagged as a network error if it is already classified as a validation error (unless its name explicitly denotes it as a Fetch/Network error). Added regression tests to ensure standard error checks (like 'fetch failed' or 'invalid email') continue to function correctly.Validation: Ran
pnpm run build,pnpm test:format,pnpm test:lint,pnpm test:types,pnpm test:knip, and targetedpnpm test:ava source/utils/error-formatter.spec.ts. All passed.Fixes #1136
Fixes #1136