I’m trying to debug my quite complex job code and when I get an exception like
TypeError: Cannot read property ‘get’ of undefined
I can’t find the code line where the problem appeared - there is no stack trace.
Also the same is with triggers. I need to console log and binary eliminate places where it could appear - it’s really annoying.
The only code showing stack trace is a Cloud Functions - which is good.
How do you guys debug jobs and triggers? Maybe I’m doing something wrong?
Why it’s not showing a full stack trace with my code and line, is that some parse Node.js engine problem?
The best way is setting up a local development environment for debugging and avoid debugging directly in the server. Once you have it running on your local machine, it would be the same of debugging a regular Node.js app.
I’m debugging it locally, it doesn’t mean that I can tell which line of code is causing the problem in my cloud job. It’s like debugging in C which I was doing 20 years ago. I would expect something more user friendly in the 21st century.
Since you are debugging it in your local machine, you should be able to see the line of code and also the complete error stack. Are you using any IDE for debugging?
@avramo, for security reasons triggers and cloud code functions do not return stack trace to client. Also returning unexpected errors to client is not considered as a best practice today.
To avoid headache and avoiding returning stack trace to client I can suggest you to put a try catch around your code and handle properly the error depending of the error source. Then depending of the Node Env, you can add some console.error() to get the full stack trace I hope it can help
Moumouls, thank you but I can get the cloud code function stack trace, and I can’t get the stack trace of Triggers and Jobs. Maybe I’m doing something wrong?
Ok I double checked and you are right, it works for the Jobs, but for the Triggers I’m sure it shows some strange stack trace without my file reference. I’ll also check it once again.
Ok, just checked and Jobs are good, but triggers gets me something like this:
ERROR ParseError: TypeError: Cannot read property ‘get’ of undefined
at error (/Workspace/parse-server/node_modules/parse-server/lib/triggers.js:381:16)
at processTicksAndRejections (node:internal/process/task_queues:93:5) {
code: 141
}
I’m not able to find the line in code easily without printing between the lines and trying to find the line code with the bug.
Here is just a basic sample.
I would just like to get code line number 9 in file Teams.js in the details of exception of the trigger but I’m getting:
at error (/Workspace/parse-server/node_modules/parse-server/lib/triggers.js:381:16)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
So no reference to my code file and it’s hard to guess where the problem is if there is many more lines of code in the trigger. I think I’m going to remove all the triggers code and create cloud functions because it seems to be very hard to maintain in case of errors.
I believe you should have the error logged twice in your console. The first one in the way you expect to be and the other that you shared. If you remove the line 12, what do you have logged in your console?
I’m only rethrowing it - If I wouldn’t do it then the record would be saved and I don’t want it to be saved if I throw an exception. Besides it’s not related.
No worries! As for the cloud stuff - according to @dplewis in the PR I made around the tracing improvements, it might be easier to trace using directAccess: true