Skip to content

Commit

Permalink
Improve castError handling of non strings (#13315)
Browse files Browse the repository at this point in the history
This pull removes castError from reduxRoutine and just passes along the value thrown instead of potentially coercing to an error.  

- Exposes values to consuming code.
- Less opinionated about what happens with the error.
  • Loading branch information
nerrad authored and youknowriad committed Mar 6, 2019
1 parent 53067fd commit e884509
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 39 deletions.
4 changes: 3 additions & 1 deletion packages/redux-routine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

### Bug Fixes

- Fix unhandled promise rejection error caused by returning null from registered generator ([#13314](https://github.com/WordPress/gutenberg/pull/13314)
- Fix unhandled promise rejection error caused by returning null from registered generator ([#13314](https://github.com/WordPress/gutenberg/pull/13314))
- The middleware will no longer attempt to coerce an error to an instance of `Error`, and instead passes through the thrown value directly. This resolves issues where an `Error` would be thrown when the underlying values were not of type `Error` or `string` (e.g. a thrown object) and the message would end up not being useful (e.g. `[Object object]`).
([#13315](https://github.com/WordPress/gutenberg/pull/13315))

## 3.0.3 (2018-10-19)

Expand Down
14 changes: 0 additions & 14 deletions packages/redux-routine/src/cast-error.js

This file was deleted.

6 changes: 1 addition & 5 deletions packages/redux-routine/src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import isPromise from 'is-promise';
/**
* Internal dependencies
*/
import castError from './cast-error';
import { isActionOfType, isAction } from './is-action';

/**
Expand All @@ -27,10 +26,7 @@ export default function createRuntime( controls = {}, dispatch ) {
const routine = control( value );
if ( isPromise( routine ) ) {
// Async control routine awaits resolution.
routine.then(
yieldNext,
( error ) => yieldError( castError( error ) ),
);
routine.then( yieldNext, yieldError );
} else {
next( routine );
}
Expand Down
18 changes: 0 additions & 18 deletions packages/redux-routine/src/test/cast-error.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/redux-routine/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe( 'createMiddleware', () => {
try {
yield { type: 'WAIT_FAIL' };
} catch ( error ) {
expect( error.message ).toBe( 'Message' );
expect( error ).toBe( 'Message' );
}
}

Expand Down

0 comments on commit e884509

Please sign in to comment.