Skip to content

Commit 90bf4cb

Browse files
authored
feat: change invoke CMS Events to throw Error (#5813)
1 parent 0895336 commit 90bf4cb

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

packages/netlify-cms-core/src/lib/__tests__/registry.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ describe('registry', () => {
170170
expect(handler).toHaveBeenCalledTimes(2);
171171
expect(handler).toHaveBeenLastCalledWith(data, options2);
172172
});
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+
});
173186
});
174187

175188
it(`should return an updated entry's DataMap`, async () => {

packages/netlify-cms-core/src/lib/registry.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,10 @@ export async function invokeEvent({ name, data }) {
246246

247247
let _data = { ...data };
248248
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 };
257253
}
258254
}
259255
return _data.entry.get('data');

0 commit comments

Comments
 (0)