Closed
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest version of Parse Server.
Issue Description
Parse Server crashes when throwing inside a Cloud Code trigger. The crash is due to the removal of the UnhandledPromiseRejectionWarning
in Node 15. Parse Server handles trowing inside a Cloud Code function differently and returns a Parse error without crashing the server.
Breaking Change
This change is breaking because developers may have implemented their own solution by globally catching unhandled rejections on the node process with:
process.on('unhandledRejection', (reason, promise) => {
// handle error
});
Steps to reproduce
This test fails:
it('does not crash server when throwing in afterLogout hook', async () => {
let triggered = false;
const error = new Error('throw in cloud code');
Parse.Cloud.afterLogout(() => {
triggered = true;
throw error;
});
await Parse.User.signUp('user', 'pass');
const response = await Parse.User.logOut().catch(e => e);
expect(triggered).toBeTrue();
expect(response).toBeDefined();
expect(response.code).toBe(141);
expect(response.message).toBe(error.message);
});
However, throwing in a Cloud Code function passes the test:
it('does not crash server when throwing in cloud code function', async () => {
const error = new Error('throw in cloud code');
Parse.Cloud.define('hello', () => {
throw error;
});
const response = await Parse.Cloud.run('hello').catch(e => e);
expect(response).toBeDefined();
expect(response.code).toBe(141);
expect(response.message).toBe(error.message);
});
Actual Outcome
Throwing in trigger crashes server.
Expected Outcome
Throwing in trigger returns Parse error without crashing the server.
Environment
Server
- Parse Server version: 5.3.0-alpha.30