joystick icon indicating copy to clipboard operation
joystick copied to clipboard

Add catcher() method to UI and Node

Open rglover opened this issue 4 months ago • 0 comments

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.

rglover avatar Aug 20 '25 17:08 rglover