parse-community / Parse-SDK-JS

The JavaScript SDK for Parse Platform
https://parseplatform.org
Apache License 2.0
1.32k stars 597 forks source link

Unhandled Promise rejection for ParseUser save() #1386

Open tboily opened 3 years ago

tboily commented 3 years ago

New Issue Checklist

Issue Description

If an error is thrown by Parse-Server on a Parse.User.save(), the SDK does not catch it and an Unhandled Promise Rejection error is raised, making it impossible for our app to catch the error.

There may be some sort of wrapper I am not aware of, but I gave a quick look to the code and to the untrained eye, it simply looks as though there is no try-catch block in the save() method of ParseUser (src/ParseUser.js). Same goes for other methods like destroy().

According to logs, error is raised at ParseObject.js:3137, but the absence of ParseUser in the error stack gives me the feeling it is indeed the culprit.

Steps to reproduce

In our case, we did as follows: Update a user with an email already used and call save().

// user is an instance of Parse.User()
try {
    user.email = 'alreadyInDb@test.com';
    await user.save()
} catch (err) {
    // We know there is an error but we never end up here because user's save() does not throw.
    throw err;
}

Actual Outcome

Logs show an unhandled promise rejection, and nothing is caught in our catch block.

Expected Outcome

The SDK should catch the error and throw it back to the app.

Environment

nodejs 12.16.1 parse 3.3.0 parse-server 4.5.0

We were working with earlier versions of parse and parse-server before and updated to the latest versions to see if this error was fixed.

Server

Database

Client

Logs

(node:10) UnhandledPromiseRejectionWarning: Error: Account already exists for this email address.
      at /workspace/node_modules/parse/lib/node/ParseObject.js:3137:35
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:10) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)
(node:10) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
dplewis commented 6 months ago

@mtrezza I can't replicate this issue. user.email = 'alreadyInDb@test.com'; not sure how this works since a setter for this doesn't exist.

mtrezza commented 6 months ago

If two users are saved with identical email addresses, is that the error that is mentioned?

dplewis commented 6 months ago

Yeah but using the example posted I can't get Unhandled Promise rejection or the error.

mtrezza commented 6 months ago

If you just save two users with identical email addresses, do you get an Unhandled Promise rejection error?