Skip to content

fix(common): add componentDidCatch logging and onError callback to ErrorBoundary (#11) - #85

Open
ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/error-boundary-logging
Open

fix(common): add componentDidCatch logging and onError callback to ErrorBoundary (#11)#85
ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/error-boundary-logging

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 2, 2026

Copy link
Copy Markdown

Problem

src/components/common/ErrorBoundary.tsx implemented getDerivedStateFromError to transition state and show fallback UI, but lacked componentDidCatch(error, info) to log the caught error to console.error or forward to diagnostic/monitoring callbacks. In production, component render crashes were completely silent and untraceable.

Fix

  1. componentDidCatch: Added componentDidCatch(error: Error, info: ErrorInfo) to log errors via console.error("[ErrorBoundary] Caught render error:", error, info.componentStack).
  2. onError callback hook: Added optional onError?: (error: Error, info: ErrorInfo) => void prop to ErrorBoundaryProps to allow forwarding caught errors to error-tracking services (e.g. Sentry/LogRocket).
  3. Reset state: Updated "Try again" click handler to clear both hasError: false and error: undefined.
  4. Test coverage: Created src/components/common/ErrorBoundary.test.tsx verifying:
    • Normal rendering of children when healthy.
    • componentDidCatch logging to console.error and default fallback UI rendering on render error.
    • Calling optional onError callback with error and component stack info.
    • Custom fallback rendering when fallback prop is provided.

Verification

  • npx vitest run src/components/common/ErrorBoundary.test.tsx (4/4 passed)
  • npx vitest run (117/117 passed across all 28 test suites)
  • npx tsc --noEmit (clean)
  • npm run build (succeeded)

Closes #11

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.

ErrorBoundary silently discards caught errors with no logging or reporting

1 participant