Giter Site home page Giter Site logo

Error handling about nanostate HOT 4 OPEN

choojs avatar choojs commented on May 26, 2024 2
Error handling

from nanostate.

Comments (4)

kareniel avatar kareniel commented on May 26, 2024 1

I wouldn't.

Better make sure the string passed to machine.emit() is a registered event in the first place.

Here's a line from the choo readme that summarizes why:

We use the require('assert') module from Node core to provide helpful error messages in development. In production you probably want to strip this using unassertify.

Do you feel like there would be a good case for managing invalid transitions internally?

I could imagine two ways this could work. Maybe:

  1. we could emit an event. a nanostate instance is already an event emitter which means .on is already exposed; the pattern should probably be: machine.on('error', ...)
  2. we could return a list of all possible states so that consumer can run the check in the application code. this comes at the cost of being tiny. maybe it's worth it? i don't know ¯\(ツ)

For now I try to make sure I emit only registered event names.

I hope this helps :)


edit:
found these thoughts on the subject:

  1. /javascript-state-machine/docs/error-handling.md

from nanostate.

vorg avatar vorg commented on May 26, 2024 1

from nanostate.

yoshuawuyts avatar yoshuawuyts commented on May 26, 2024

@vorg hey, yeah - so the idea behind throwing an error here is that you've made a mistake in the logic. In any given scenario, if you hit an invalid transition, there's no good way to recover from that. Which state did you intend to go? Which state should we be in to recover? There's no good answer.

So we throw, and hope a developer spots the mistake and fixes the source.

As per choojs/nanocomponent#43 for use within nanocomponent, we'll have error boundaries in the (near) future. These are basically try..catch blocks around all internal methods, calling an optional error handler if something goes wrong.

Does this make sense?

from nanostate.

bcomnes avatar bcomnes commented on May 26, 2024

I'm going to prioritize that next, should be a fairly easy addition.

from nanostate.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.