Skip to content

Returning undefined in cloud code throws error #5053

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
dplewis opened this issue Sep 14, 2018 · 9 comments
Closed

Returning undefined in cloud code throws error #5053

dplewis opened this issue Sep 14, 2018 · 9 comments

Comments

@dplewis
Copy link
Member

dplewis commented Sep 14, 2018

Issue Description

Similar to parse-community/Parse-SDK-JS#417

Steps to reproduce

Parse.Cloud.define('returnUndefined', () => {
  return undefined;
});

Expected Results

return undefined / null
not throw error

Actual Outcome

Unhandled Promise Rejection: Error: The server returned an invalid response.

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 3.0.0
    • Operating System: Mac OSX
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): localhost
  • Database

    • MongoDB version: Mongo
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): localhost

Logs/Trace

info: Ran cloud function returnUndefined for user undefined with:
  Input: {}
  Result: undefined functionName= returnUndefined, , user=undefined
verbose: RESPONSE from [POST] /parse/functions/returnVoid: {
  "response": {}
} result=undefined
@SebC99
Copy link
Contributor

SebC99 commented Oct 20, 2018

We've discussed this here:
#4818

@dplewis
Copy link
Member Author

dplewis commented Oct 20, 2018

@SebC99 PR? @flovilmart is forcing return null ok?

@SebC99
Copy link
Contributor

SebC99 commented Oct 20, 2018

@dplewis there was no real consensus on the solution and on the impact on SDKs:

  • solution 1: return null instead of undefined before stringifying the json. Should have no impact on SDK as null would be understand well in JS and iOS (I don't know for Android)
  • solution 2: just display a warning on server side to avoid undefined results, but we will still have the issue
  • solution 3: add a status field next to the result field in the json to avoid empty json, which could be ignore by SDKs at first to have no impact.

@flovilmart
Copy link
Contributor

Do we need to address that? Or we’re bikeshedding for nothin? I have no trouble considering undefined as an invalid response :)

@dplewis
Copy link
Member Author

dplewis commented Oct 20, 2018

The rest api returns {}, iOS returns null, JS returns unhandled promise rejection.

We can at least get rid of the unhandled rejection with a catch

https://github.com/parse-community/Parse-SDK-JS/blob/master/src/Cloud.js#L129

@flovilmart
Copy link
Contributor

Uhm ok. On iOS can you show me the equivalent code?

@flovilmart
Copy link
Contributor

alright, that kinda sucks, as in iOS it ends up being decode:nil.

let's support it on the JS SDK.

@dplewis
Copy link
Member Author

dplewis commented Oct 21, 2018

Closed via parse-community/Parse-SDK-JS#682

@dplewis dplewis closed this as completed Oct 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants