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

[core] feat(interpreter): allow to provide errorListeners #2841

Closed
wants to merge 17 commits into from

Conversation

roggervalf
Copy link

This PR tries to handle this missing feature, where error listeners were not attached.

@changeset-bot
Copy link

changeset-bot bot commented Nov 28, 2021

🦋 Changeset detected

Latest commit: 865f2ce

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
xstate Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ghost
Copy link

ghost commented Nov 28, 2021

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

Comment on lines 1089 to 1091
if (this.errorListeners.size) {
this.sendError(error);
}
Copy link
Member

Choose a reason for hiding this comment

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

There are more places where errors could happen and I think they should be covered as well IF we decide to add this feature.

I think that in general there might be a need for a top-level onError listener but we should think carefully through how this works with multiple nested machines etc.

Copy link
Author

Choose a reason for hiding this comment

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

thank you @Andarist, I tried to update my pr, please when you get a chance 👀 to take a look

Copy link

Choose a reason for hiding this comment

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

There are more places where errors could happen and I think they should be covered as well IF we decide to add this feature.

Could you help us to find those places where the errors could happen please?

@Visot
Copy link

Visot commented Nov 30, 2021

Interesting that the errorListener is missing, I was also wondering why errors were not appearing, any chance to have a fix for it?

@roggervalf
Copy link
Author

Interesting that the errorListener is missing, I was also wondering why errors were not appearing, any chance to have a fix for it?

hi @Visot, I'm still trying to do it in this pr

@@ -552,13 +583,22 @@ export class Interpreter<
*/
public send = (
event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>,
payload?: EventData
payload?: EventData,
sendError = false
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove this; errors should either be unhandled error.* events or "natural" errors thrown from execution of the machine.

Copy link
Author

Choose a reason for hiding this comment

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

thank you @davidkpiano I just see your message, in my last commit I was replacing this by checking the type in the event, is that ok or should I do in a different way?

@Visot
Copy link

Visot commented Dec 6, 2021

+1 on this one, super useful if implemented

reportUnhandledExceptionOnInvocation(errorData, error, id);
if (this.parent) {
this.parent.send({
type: 'xstate.error',
Copy link
Author

@roggervalf roggervalf Dec 11, 2021

Choose a reason for hiding this comment

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

@davidkpiano could you please help me in this case, is it ok this type of error or should it be a different one?

@roggervalf roggervalf changed the title feat(interpreter): allow to provide errorListeners [core] feat(interpreter): allow to provide errorListeners Dec 17, 2021
Copy link

@eliecerUribe eliecerUribe left a comment

Choose a reason for hiding this comment

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

Very useful feature for this. Good job! 💯

@manast
Copy link

manast commented Jan 10, 2022

What's left in order to get this PR merged?

@@ -559,6 +590,14 @@ export class Interpreter<
return this.state;
}

if (((event as EventObject)?.type || '').includes('error')) {
Copy link
Member

Choose a reason for hiding this comment

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

If anything - this should be checked on the _event (and on the appropriate field). It might be "too soon" to check this as the event might not be an EventObject, it actually might be already a SCXML.Event.

This should also check if the type/name of the event starts with error. and not if the type contains an error substring.

also, a nit: optional chaining here and defaulting this to an empty string seems unnecessary:

  • the event parameter is required
  • all events should have valid types/names

Copy link
Author

Choose a reason for hiding this comment

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

thank you, I updated it

if (this.parent) {
this.parent.sendError(event as any);
} else {
this.sendError(event as any);
Copy link
Member

Choose a reason for hiding this comment

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

This one sounds like it's going to send this event somewhere (like some kind of an actor or something), but it's more like notifying current subscribers.

I also do not (overall) liking how this might make more errors to be swallowed. In general, the error story in XState is currently under-specified so it's somewhat hard to answer "how this should behave now?". I would love to hear out your thoughts about this RFC: statelyai/rfcs#4 . Going through that could also show you my perspective better.

Copy link
Author

Choose a reason for hiding this comment

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

Looks pretty nice, could you please guide me on the proper changes when you get some chance?

@Andarist
Copy link
Member

I'm sorry that this PR didn't get the attention it deserved in the past. In v5 those parts changed and I think that the issue at hand was already addressed on that branch.

@Andarist Andarist closed this Sep 13, 2023
@roggervalf roggervalf deleted the feat-errorListerners branch September 13, 2023 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants