Skip to content

fix: server crashes when throwing in Cloud Code trigger #8256

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,41 @@ const mockAdapter = {
},
};

fdescribe('Error handling', () => {
const error = new Error('throw in cloud code');

it('does not crash server when throwing in cloud code function', async () => {
let triggered = false;

Parse.Cloud.define('hello', () => {
triggered = true;
throw error;
});

const response = await Parse.Cloud.run('hello').catch(e => e);
expect(triggered).toBeTrue();
expect(response).toBeDefined();
expect(response.code).toBe(141);
expect(response.message).toBe(error.message);
});

it('does not crash server when throwing in afterLogout hook', async () => {
let triggered = false;

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);
});
});

describe('Cloud Code', () => {
it('can load absolute cloud code file', done => {
reconfigureServer({
Expand Down