Skip to content
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

Server crashes when throwing inside Cloud Code trigger #8255

Closed
4 tasks done
Tracked by #8225
mtrezza opened this issue Oct 23, 2022 · 5 comments · Fixed by #8280
Closed
4 tasks done
Tracked by #8225

Server crashes when throwing inside Cloud Code trigger #8255

mtrezza opened this issue Oct 23, 2022 · 5 comments · Fixed by #8280
Labels
state:breaking Breaking change requires major version increment and `BREAKING CHANGE` commit message state:released Released as stable version state:released-beta Released as beta version type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@mtrezza
Copy link
Member

mtrezza commented Oct 23, 2022

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

@parse-github-assistant
Copy link

parse-github-assistant bot commented Oct 23, 2022

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Oct 23, 2022
@mtrezza mtrezza added block:major Needs to be resolved before next major release; remove label afterwards state:breaking Breaking change requires major version increment and `BREAKING CHANGE` commit message and removed state:breaking Breaking change requires major version increment and `BREAKING CHANGE` commit message labels Oct 31, 2022
@mtrezza mtrezza removed the block:major Needs to be resolved before next major release; remove label afterwards label Nov 10, 2022
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.0.0-alpha.5

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Nov 10, 2022
@parse-github-assistant
Copy link

The label state:released-alpha cannot be used in combination with state:breaking.

@parse-github-assistant parse-github-assistant bot removed the state:released-alpha Released as alpha version label Nov 10, 2022
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.0.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Jan 31, 2023
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.0.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:breaking Breaking change requires major version increment and `BREAKING CHANGE` commit message state:released Released as stable version state:released-beta Released as beta version type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
2 participants