Error Handling
How @fcannizzaro/streamdeck-react handles component errors, render failures, and recovery.
Component Errors
When a component throws during render, the library catches it at the root level and:
- Logs the error via
console.error('[@fcannizzaro/streamdeck-react] Component error: ...'). - Renders a fallback error image (red background with "Error" text).
- Does not crash the plugin -- other action instances continue working.
User Error Boundaries
Use the built-in ErrorBoundary component for granular error handling within your components:
import { ErrorBoundary } from '@fcannizzaro/streamdeck-react';
function SafeKey() {
return (
<ErrorBoundary
fallback={<ErrorFallback />}
onError={(error, info) => {
console.error('Caught:', error);
}}
>
<RiskyComponent />
</ErrorBoundary>
);
}Root Error Boundary
Every action root is automatically wrapped in an error boundary. If a component throws:
- The key/dial shows a red error indicator.
- The error is logged.
- All other action instances continue working.
Custom Error Callback
Use onActionError in createPlugin for custom error reporting:
const plugin = createPlugin({
// ...
onActionError: (uuid, actionId, error) => {
myErrorTracker.report(error);
},
});Render Errors
If rendering fails because of invalid JSX structure, unsupported styling, or image generation issues, the error is caught the same way -- logged and replaced with a fallback image. The plugin continues running.
Best Practices
- Wrap risky code (network calls, external data parsing) in error boundaries.
- Use
onActionErrorfor centralized error reporting. - Keep component trees simple to minimize renderer edge cases.
- Test components with various data states, including empty/null values.