Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement basic error tolerance (WIP) #2287

Closed
wants to merge 1 commit into from

Conversation

dead-claudia
Copy link
Member

Description

I deferred all hook errors to the end (after we render) and I just rethrow the last one we catch. This is so if an error occurs, things still get logged rather than breaking.

Note that if onbeforeupdate throws, I don't update the children. This is the only case where I don't treat throwing identically to undefined, but if we don't know if we could update without error, we should err to the side of caution and just not try.

Motivation and Context

Fixes #1937

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation change

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated docs/change-log.md

@dead-claudia dead-claudia added the Type: Bug For bugs and any other unexpected breakage label Nov 7, 2018
@dead-claudia dead-claudia added this to the 2.0.0 milestone Nov 7, 2018
@dead-claudia
Copy link
Member Author

I've got this milestoned for v2, but it's not an absolute blocker. Anything here is technically non-breaking and falls in the realm of a bug fix, so we could ship it in v2.0.1 if necessary.

@dead-claudia dead-claudia force-pushed the error-fix branch 3 times, most recently from 85f7e60 to 7fc6fba Compare November 9, 2018 19:21
@dead-claudia dead-claudia force-pushed the error-fix branch 2 times, most recently from 04334a4 to 4eed22d Compare November 30, 2018 09:32
@pygy
Copy link
Member

pygy commented Dec 14, 2019

Using the closure for state would make m.render non-reentrant.

Not sure it is documented, but I've relied on that property in the past to implement React Portal-like components in Mithril.

I'll look at the meat of the patch later this evening.

@dead-claudia
Copy link
Member Author

dead-claudia commented Dec 14, 2019 via email

@pygy pygy self-requested a review December 14, 2019 19:39
@pygy
Copy link
Member

pygy commented Dec 14, 2019

Indeed, I had missed that bit. Good point, and nice implementation. +1 for doubling down with the NS parameter.

Copy link
Member

@pygy pygy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous discussions went over my head, actually, I couldn't see how to do something useful to tackle the issue. Now I see :-)

I like the approach in general, but I have reservations for the method used to report the errors.

Also I wonder if it is complete: is the lack of hookThrown detection in onremove() deliberate?

Tests will also be needed (I can help).

@@ -138,8 +150,9 @@ module.exports = function($window) {
}
}
}
function initComponent(vnode, hooks) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the last remnant of the vnode cache... Good riddance I guess :-)

hookErrors = prevHookErrors
if (nextHookThrown) {
var message = "Errors occurred during rendering:"
for (var i = 0; i < nextHookErrors.length; i++) message += "\n" + nextHookErrors[i].message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we rather use console.error(nextHookErrors[i]) so that the stack is available and interactive in the console, then throw "Errors occurred during rendering"?

@dead-claudia
Copy link
Member Author

dead-claudia commented Dec 19, 2019

@pygy I'll file a new PR with a version that actually works with the current system - it's an utter mess and the push/restore bits would need to integrate with the redraw bits as well. I also have to errors during removal (both sync and async) better - they should be swallowed, but logged, and the logging part should also be a setting you can set. (I'll want to update the third parameter to m.redraw to accept either a {redraw, onerror} object or a redraw function.) Edit: I decided against this. See my new comment in #1937.

Separately, and I'll file this in the main issue, I found a way to add error handling without breaking things, but it'll require a fragment-like control vnode, something that'll be a bit new (providing a small preview of what the redesign will end up looking like). Edit: Link to proposal.

@dead-claudia dead-claudia deleted the error-fix branch September 25, 2024 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug For bugs and any other unexpected breakage
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

Error handling in view
2 participants