Repository navigation
Server error when throw exception in beforeSave hook #5063
Copy link
Copy link
Closed
Description
Issue Description
I tried to abort a save action in beforeSave hook, following instruction, and got http 500 for this request.
Steps to reproduce
Parse.Cloud.beforeSave('Master', async (req) => {
throw new Error('cya');
});then update a Master object using the dashboard or js client.
Expected Results
client got an error with message cya.
Actual Outcome
client got body {"code":1,"message":"Internal server error."} with http code 500.
After that client tried 4 more times and then gave up.
Environment Setup
-
Server
- parse-server version (Be specific! Don't say 'latest'.) : 3.0.0
- Operating System: linux
- Hardware: x86_64
- Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): localhost
-
Database
- MongoDB version: mongodb 3.6.5 WiredTiger: 3.0.1: (January 8, 2018)
- Storage engine: wiredtiger
- Hardware: the same with server
- Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): the same with server
Logs/Trace
error: beforeSave failed for Master for user undefined:
Input: xxxxxxxx... (truncated)
Error: {} className=Master, triggerType=beforeSave, , user=undefined
error: Uncaught internal server error. Error: cya
at _callee$ (/home/xxxxx/src/parse/cloud.js:7:11)
at tryCatch (/home/xxxxx/node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (/home/xxxxx/node_modules/regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as next] (/home/xxxxx/node_modules/regenerator-runtime/runtime.js:114:21)
at step (/home/xxxxx/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /home/xxxxx/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14
at new Promise (<anonymous>)
at new F (/home/xxxxx/node_modules/core-js/library/modules/_export.js:35:28)
at /home/xxxxx/node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12
at /home/xxxxx/src/parse/cloud.js:5:1
at Promise.resolve.then (/home/xxxxx/node_modules/parse-server/src/triggers.js:438:23)
at process._tickCallback (internal/process/next_tick.js:68:7) Error: cya
at _callee$ (/home/xxxxx/src/parse/cloud.js:7:11)
at tryCatch (/home/xxxxx/node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (/home/xxxxx/node_modules/regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as next] (/home/xxxxx/node_modules/regenerator-runtime/runtime.js:114:21)
at step (/home/xxxxx/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /home/xxxxx/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14
at new Promise (<anonymous>)
at new F (/home/xxxxx/node_modules/core-js/library/modules/_export.js:35:28)
at /home/xxxxx/node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12
at /home/xxxxx/src/parse/cloud.js:5:1
at Promise.resolve.then (/home/xxxxx/node_modules/parse-server/src/triggers.js:438:23)
at process._tickCallback (internal/process/next_tick.js:68:7)
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:470:11)
at ServerResponse.header (/home/xxxxx/node_modules/parse-server/node_modules/express/lib/response.js:767:10)
at ServerResponse.send (/home/xxxxx/node_modules/parse-server/node_modules/express/lib/response.js:170:12)
at ServerResponse.json (/home/xxxxx/node_modules/parse-server/node_modules/express/lib/response.js:267:15)
at errorHandler (/home/xxxxx/src/errorHandler.js:4:24)
at Layer.handle_error (/home/xxxxx/node_modules/express/lib/router/layer.js:71:5)
at trim_prefix (/home/xxxxx/node_modules/express/lib/router/index.js:315:13)
at /home/xxxxx/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/xxxxx/node_modules/express/lib/router/index.js:335:12)
at next (/home/xxxxx/node_modules/express/lib/router/index.js:275:10)
at Layer.handle_error (/home/xxxxx/node_modules/express/lib/router/layer.js:67:12)
at trim_prefix (/home/xxxxx/node_modules/express/lib/router/index.js:315:13)
at /home/xxxxx/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/xxxxx/node_modules/express/lib/router/index.js:335:12)
at next (/home/xxxxx/node_modules/express/lib/router/index.js:275:10)
at Layer.handle_error (/home/xxxxx/node_modules/express/lib/router/layer.js:67:12)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
flovilmart commentedon Sep 19, 2018
What version of node are you using? And why is your stacktrace riddled with regenerator runtime calls?
reallyimeric commentedon Sep 19, 2018
@flovilmart node version is
v10.10.0. I'm using babel.This is my gulpfile:
I'm using
babel-nodein dev.flovilmart commentedon Sep 19, 2018
@reallyimeric this is working fine in our tests: https://github.com/parse-community/parse-server/blob/803c6d2/spec/CloudCode.spec.js#L54
Both on node 8 and node 10. You should probably not use
transform-runtimenor babel as it's clearly producing some code that doesn't work.flovilmart commentedon Sep 19, 2018
my bad, this is actually yielding the same issue as yours, use
return Promise.reject();orthrow new Parse.Error(-1, 'My Error')you can replace -1 with the error code of your choice.Even better, you can open a PR with the potential fix.
reallyimeric commentedon Sep 19, 2018
I have submitted a pr. By the way,
return Promise.reject();leads toa response of http 401parse server middleware passing control to the next express middleware (return 401 for my instance).flovilmart commentedon Sep 19, 2018
This should be resolved with your fix no? Depending on the type inside the rejection. If you don’t pass anything, then it’s probably what you’re experiencing. Do you happen to have logs for this?
reallyimeric commentedon Sep 20, 2018
Yes it was. I have not digged into that before.
jeremypiednoel commentedon Oct 4, 2018
Hi Guys I have the same issue, Thanks @reallyimeric for the fix.
Do you guys know when it will be released ?
Thanks.
acinader commentedon Oct 18, 2018
fixed by #5064