joystick
joystick copied to clipboard
Add catcher() method to UI and Node
Something like this:
import { catcher } from '@joystick.js/ui'
const result = catcher(() => {
if (Math.random() > 0.5) {
throw new Error('Boom!')
}
return 'ok'
}, {
on_error: (error) => {
console.error('Caught in catcher:', error.message)
return 'fallback'
},
});
Why? So we can standardize error handling and plumbing. This is just a thin wrapper that enforces usage of a try/catch internally. The point being that the naming of the function makes it easy to memorize and encourages proper error handling (for next to zero cost).
We take a small hit on extra syntax, however, we gain an easy-to-remember, easy-to-use pattern that encourages good behavior > bad behavior.