Skip to content

#314 AnchorsPanel mirrors every registerAnchor failure onto AnchorFor…#402

Open
felladaniel36-hash wants to merge 1 commit into
AnchorNet-Org:mainfrom
felladaniel36-hash:#314-AnchorsPanel-mirrors-every-registerAnchor-failure-onto-AnchorForm's-id-field,-even-unrelated/generic-errors-FIX
Open

#314 AnchorsPanel mirrors every registerAnchor failure onto AnchorFor…#402
felladaniel36-hash wants to merge 1 commit into
AnchorNet-Org:mainfrom
felladaniel36-hash:#314-AnchorsPanel-mirrors-every-registerAnchor-failure-onto-AnchorForm's-id-field,-even-unrelated/generic-errors-FIX

Conversation

@felladaniel36-hash

Copy link
Copy Markdown

Description

Closes #314 - Fixes error attribution bug in AnchorsPanel.register() -> AnchorForm id field.

What was happening:
AnchorsPanel.tsx:register() caught any failure from registerAnchor() and did:

const message = err instanceof Error ? err.message : "Registration failed";
notify("error", message);
setServerError(message); // <- unconditional

AnchorForm.tsx useEffect mirrors serverError onto id field as aria-invalid=true with inline red text.
So a transient network error, 503, timeout, or any generic 5xx was displayed as if the user-entered Anchor id was invalid.

What this PR does:

  1. Core fix – src/components/AnchorsPanel.tsx

    • Restored file lost in bad merge e902edb (serverError state, debouncedQuery, filterRefs, onFilterKeyDown).
    • Import ApiRequestError and only surface id-specific failures inline:
      if (err instanceof ApiRequestError && (err.status===409 || err.code==="CONFLICT")) {
        setServerError(message);
      }
    • notify("error", message) still fires for every failure type as before.
  2. Build fixes for e902edb regression

    • src/lib/api.ts: composeSignals(..., callerSignal?: AbortSignal | null)RequestInit.signal can be null.
    • src/lib/search.ts: restored AND semantics terms.every(...) broken to single-needle.
    • src/lib/settlementsApi.ts: added missing apiTextRequest import.
  3. Tests – src/components/AnchorsPanel.test.tsx

    • Updated existing "surfaces a field-level error..." to use realistic new ApiRequestError(409, "CONFLICT", "Duplicate anchor id") and asserts aria-invalid=true + inline + toast.
    • NEW does not mark id field invalid on generic registration failure but shows toast:
      • mocks registerAnchor -> Error("Network error")
      • asserts toast exists via screen.findByText("Network error")
      • asserts aria-invalid="false" and within(form).queryByText("Network error") === null

Acceptance:

  • Generic/non-id failure no longer marks id field invalid
  • Genuine 409/CONFLICT still surfaces inline
  • Toast fires for every failure

Checklist

  • I added a CHANGELOG.md entry under the next ## [x.y.z] section

    ### Fixed
    - `AnchorsPanel`: Only 409 CONFLICT errors now surface inline on Anchor id field; generic/network/5xx errors show only via toast, not as field invalid.
    - `api.ts`: Allow `null` signal in `composeSignals` to fix TS build.
    - `search.ts`: Restore AND-semantics for multi-term search.
    

    (If changelog not required for this exercise, this is internal but user-facing behavior is fixed)

  • Tests added/updated for the change.

    • 26/26 pass in AnchorsPanel.test.tsx (was 25, +1 new generic-error test)
    • search.test.ts 12/12 pass after restore

…nto AnchorForm's id field, even unrelated/generic errors FIXED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnchorsPanel mirrors every registerAnchor failure onto AnchorForm's id field, even unrelated/generic errors

1 participant