Skip to content

Empty catch blocks silently swallow errors #10

Description

@DanielCotoJ

Summary

Several catch blocks discard the caught error without logging it or notifying
the user. When clipboard, wallet, or DID operations fail, nothing happens —
making real failures invisible and very hard to debug in production.

Affected code

Note: copyToClipboard in use-vault-setup.ts:57-66 calls
navigator.clipboard.writeText(text) without any try/catch or await, so a
rejected promise becomes an unhandled rejection. This should be fixed in the
same pass.

Why it's a problem

  • Users get no feedback when "Copy" silently fails (e.g. non-secure context, or
    browsers that block clipboard access).
  • A failed wallet connection in handleConnect looks identical to "nothing
    happened", confusing users.
  • Swallowed errors never reach logs or monitoring, so issues are invisible until
    a user reports them.

Step-by-step fix

  1. Standardize on the existing toast utility. The project already uses
    sonner (import { toast } from 'sonner'). Reuse it for user-facing feedback
    so the UX stays consistent.
  2. Fix copyId in vault/list/page.tsx:
    • Import toast from sonner.
    • On success, call toast.success('Copied to clipboard').
    • In the catch (e) block, call toast.error('Could not copy') and
      console.warn('Clipboard copy failed', e).
  3. Fix copyToClipboard in use-vault-setup.ts:
    • Make the callback async and await navigator.clipboard.writeText(text)
      inside a try/catch.
    • On failure, show toast.error('Could not copy') and keep the copied*
      state from flipping to true.
  4. Fix the saveComputedDid effect in use-vault-setup.ts:
    • In the catch (e) block, add console.warn('Failed to compute DID', e).
    • Optionally surface a non-blocking toast.error('Could not initialize DID').
  5. Fix handleConnect / handleDisconnect in Header.tsx:
    • In each catch (e), log with console.warn(...).
    • For handleConnect, show toast.error('Could not connect wallet') (replace
      the "swallow to avoid extra alerts" comment — a single toast is the
      intended single alert).
  6. Lint & build: run npm run lint and npm run build to confirm no
    unused-variable warnings remain from the renamed catch (e) parameters.
  7. Manual test:
    • Trigger a copy in an insecure context (or stub navigator.clipboard) and
      confirm an error toast appears.
    • Disconnect the wallet mid-connect and confirm the error is logged/toasted.

Acceptance criteria

  • No empty catch {} blocks remain in the affected files.
  • Every failure path either logs (console.warn/console.error) or shows a
    toast (preferably both).
  • navigator.clipboard.writeText calls are awaited and wrapped in try/catch.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions