Skip to content

Server crashes when throwing inside Cloud Code trigger #8255

Closed
@mtrezza

Description

@mtrezza

New Issue Checklist

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:breakingBreaking change requires major version increment and `BREAKING CHANGE` commit messagestate:releasedReleased as stable versionstate:released-betaReleased as beta versiontype:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions