File tree 2 files changed +17
-8
lines changed
packages/netlify-cms-core/src/lib
2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,19 @@ describe('registry', () => {
170
170
expect ( handler ) . toHaveBeenCalledTimes ( 2 ) ;
171
171
expect ( handler ) . toHaveBeenLastCalledWith ( data , options2 ) ;
172
172
} ) ;
173
+
174
+ it ( `should throw error when '${ name } ' handler throws error` , async ( ) => {
175
+ const { registerEventListener, invokeEvent } = require ( '../registry' ) ;
176
+
177
+ const handler = jest . fn ( ( ) => {
178
+ throw new Error ( 'handler failed!' ) ;
179
+ } ) ;
180
+
181
+ registerEventListener ( { name, handler } ) ;
182
+ const data = { entry : fromJS ( { data : { } } ) } ;
183
+
184
+ await expect ( invokeEvent ( { name, data } ) ) . rejects . toThrow ( 'handler failed!' ) ;
185
+ } ) ;
173
186
} ) ;
174
187
175
188
it ( `should return an updated entry's DataMap` , async ( ) => {
Original file line number Diff line number Diff line change @@ -246,14 +246,10 @@ export async function invokeEvent({ name, data }) {
246
246
247
247
let _data = { ...data } ;
248
248
for ( const { handler, options } of handlers ) {
249
- try {
250
- const result = await handler ( _data , options ) ;
251
- if ( result !== undefined ) {
252
- const entry = _data . entry . set ( 'data' , result ) ;
253
- _data = { ...data , entry } ;
254
- }
255
- } catch ( e ) {
256
- console . warn ( `Failed running handler for event ${ name } with message: ${ e . message } ` ) ;
249
+ const result = await handler ( _data , options ) ;
250
+ if ( result !== undefined ) {
251
+ const entry = _data . entry . set ( 'data' , result ) ;
252
+ _data = { ...data , entry } ;
257
253
}
258
254
}
259
255
return _data . entry . get ( 'data' ) ;
You can’t perform that action at this time.
0 commit comments