-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Handle resolution errors in @wordpress/data #38669
Conversation
Size Change: +4.7 kB (0%) Total Size: 1.15 MB
ℹ️ View Unchanged
|
ad0197f
to
71678cc
Compare
Haven't reviewed anything yet. Just want to say that you're a superhero, @adamziel 😍 . What would we do without you? |
f1e56e9
to
5c15583
Compare
I added a test case for falsy errors: it( 'returns true if the resolution has failed even if the error is falsy', async () => {
registry.registerStore( 'store', {
reducer: ( state = null, action ) => {
if ( action.type === 'RECEIVE' ) {
return action.items;
}
return state;
},
selectors: {
getItems: ( state ) => state,
},
resolvers: {
getItems: () => {
throw null;
},
},
} );
expect(
registry.select( 'store' ).hasResolutionFailed( 'getItems' )
).toBeFalsy();
await resolve( registry, 'getItems' );
expect(
registry.select( 'store' ).hasResolutionFailed( 'getItems' )
).toBeTruthy();
} ); |
0c77c84
to
9bbfda1
Compare
8ffdc26
to
4a28600
Compare
@jsnajdr this one is ready for another review 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this a lot! Thank you for working on this, as always!
Left some minor feedback, but generally it looks good!
…s return StateValue
This is the best and it's definitely required. Thank you for working on this 👏 |
Do you see any blockers @youknowriad, or are we good? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Do we have any docs about the resolution/resolvers that need to be updated?
@youknowriad thanks! I added a changelog entry. Other than that I don't think the meta store is documented anywhere. I grepped all the meta selector and meta action names and didn't find any markdown documentation other than the autogenerated ones. I will make sure to include that in the new documents that I'm writing. Oh, and I wasn't sure about the dev note label but I added it anyway – let's figure it out when the time comes. |
Description
@wodrpress/data
exposes a resolvers API, but ignores any errors thrown during the resolution:gutenberg/packages/core-data/src/resolvers.js
Lines 107 to 111 in 70730e6
This PR proposes an error handling mechanism that works roughly as follows:
failResolution
action which also finalizes the resolutionhasLastResolutionFailed
andgetLastResolutionFailure
selectorsresolveSelect
will now be rejected in case of resolution error. Previously it just hanged forever.To that last point, we may need to wrap any
resolveSelect
in try/catch to make sure redux actions don't start unexpectedly throwing exceptions.Test plan
It is a new feature, so testing is mostly about confirming the CI checks, reading the code, and discussing.
cc @youknowriad @jsnajdr @mcsf @gziolo @ellatrix @draganescu @noisysocks @jsnajdr @Mamaduka @jorgefilipecosta @talldan @getdave @kevin940726 @anton-vlasenko