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

RTK errors lose cause (the page editor HTTP error log is broken) #3613

Closed
fregante opened this issue Jun 8, 2022 · 3 comments · Fixed by #3645
Closed

RTK errors lose cause (the page editor HTTP error log is broken) #3613

fregante opened this issue Jun 8, 2022 · 3 comments · Fixed by #3645
Assignees
Labels
bug Something isn't working
Milestone

Comments

@fregante
Copy link
Contributor

fregante commented Jun 8, 2022

Something (presumably RTK) is only partially serializing errors, not serialize-errors. This is an example I'm seeing in the page editor:

Screen Shot 13

The error is thrown when I try to expand this, which then crashes the app because it expects cause:

Screen Shot 14

The only place where we generate a RemoteServiceError has a cause:

throw new RemoteServiceError(getErrorMessage(error), { cause: error });

Possible solution

RTK appears to expose a serializeError option but I didn't immediately find a way to implement this in our codebase.

Related

Recently we've encountered errors that somehow lacked a cause property. Maybe around this time, but I'm not sure:

Found while looking into:

This worked three months ago:

RTK docs:

@fregante fregante added the bug Something isn't working label Jun 8, 2022
@fregante
Copy link
Contributor Author

fregante commented Jun 8, 2022

I bisected the cause back to this:

I'm guessing it's because cause is ignored by RTK now since it's non-enumerable. In practice RTK never supported non-string properties:

https://github.com/reduxjs/redux-toolkit/blob/64a30d83384d77bcbc59231fa32aa2f1acd67020/packages/toolkit/src/createAsyncThunk.ts#L98

I opened an issue upstream, but I think we should still use the custom serializeError with our own serialize-error version.

@fregante fregante changed the title RTK errors are a lost cause (the page editor HTTP error log is broken) RTK errors lose cause (the page editor HTTP error log is broken) Jun 8, 2022
@twschiller
Copy link
Contributor

twschiller commented Jun 9, 2022

Something (presumably RTK) is only partially serializing errors, not serialize-errors. This is an example I'm seeing in the page editor:

Not sure if I'm understanding, but the network errors are serialized here:

error: serializeError(error, { useToJSON: false }),

It's using the serializeError method from serialize-error

@twschiller twschiller added this to the 1.7.0 milestone Jun 9, 2022
@twschiller
Copy link
Contributor

twschiller commented Jun 10, 2022

Something (presumably RTK) is only partially serializing errors, not serialize-errors

The HTTP error log show bricks errors, which aren't calls made via RTK Query. They would be made through the background worker's proxyService method with Axios

The serialization would happen at either: 1) the messenger boundary, and/or 2) storing the error in IDB with recordLog, 3) when the log record is read from IDB and placed in the Redux Slice (which we use RTK to write)

In cases 1/2, I would imagine any non-enumerable/serialized props would get dropped. For 3, Redux puts whatever you throw at it in the Redux Store, but has middleware that will show a warning.

My hunch is it's probably No 2. not accounting for it right now.

IDB contents currently:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants