mithril.js icon indicating copy to clipboard operation
mithril.js copied to clipboard

routeResolver.onmatch swallows errors

Open sjmik opened this issue 6 years ago • 2 comments

Mithril version: 2.0.3

Browser and OS: Chrome 76 on Win 10

Code

Flems

m.route(document.body, '/', {
  '/': {
    render() { return m('h3', 'Home page'); }
  },
  '/other': {
    onmatch() { p('do something crazy'); x.y; p('done?'); },
    render() { return m('h3', 'Other page'); }
  }
});
m.route.set('other');

Steps to Reproduce

  1. Run the code.
  2. Look at the JS console.

Expected Behavior

Not sure what behavior should happen, but I do expect to see the error in the JS console.

Current Behavior

Routed to default route and no error is shown in the JS console.

Context

Makes it difficult to debug why an application is behaving in an unexpected way when you can't see the underlying error.

sjmik avatar Sep 19 '19 16:09 sjmik

Pretty sure this is somewhat intentional, but not entirely. What it could do is rethrow the error on rejection, so it acts more properly like a finally.

dead-claudia avatar Sep 22 '19 07:09 dead-claudia

I didn't design that part of the router, BTW. So I'm not sure what the rationale was, if it was in fact by design. I don't believe this part is tested for, so it might have been an oversight.

dead-claudia avatar Sep 22 '19 07:09 dead-claudia