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

Thrown errors in client sagas are now logged to console. #2087

Merged
merged 1 commit into from
Feb 28, 2020

Conversation

tonyanziano
Copy link
Contributor

@tonyanziano tonyanziano commented Feb 27, 2020

This will help debug issues like #2086

===

Due to the way sagas work, the errors thrown in our nested sagas are seen as uncaught and redux saga hides most of the internal properties of the thrown error and just shows the message, which isn't very helpful.

redux-saga provides an onError hook that you can use for catching these errors at the root level, but the onError will only get called if the caught error is of type Error. Since we defined our own error type ResponseError the onError hook never gets called. We need to update to redux-saga@1.0.0 for that check to be fixed, but this might incur some other breaking changes that I don't think this PR should deal with. See this issue for reference.

For now, we will surface the error in its entirety through console.error().

Before the change:

saga-err-before

After the change:

saga-err-after

@@ -50,13 +50,18 @@ export function* throwErrorFromResponse(errorMessage: string, response: Response
status,
};
if (text) {
const errText = yield text();
const errText = yield text.call(response);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was also throwing the following error:

TypeError: Failed to execute 'text' on 'Response': Illegal invocation

because text() was being called outside of the response context.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is good for now. But we just do a try catch block around all our sagas and log them.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 68.165% when pulling 3126dd1 on toanzian/restart-fix into 49f2346 on master.

@@ -50,13 +50,18 @@ export function* throwErrorFromResponse(errorMessage: string, response: Response
status,
};
if (text) {
const errText = yield text();
const errText = yield text.call(response);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is good for now. But we just do a try catch block around all our sagas and log them.

@tonyanziano
Copy link
Contributor Author

tonyanziano commented Feb 28, 2020

@srinaath once we bump react-saga to 1.0.0+ we can use the top-level onError hook to accomplish this

https://redux-saga.js.org/docs/basics/ErrorHandling.html

@tonyanziano tonyanziano merged commit 6b8b532 into master Feb 28, 2020
@tonyanziano tonyanziano deleted the toanzian/restart-fix branch February 28, 2020 18:03
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.

None yet

3 participants