When an error is thrown, the stacktrace consists of a relevant error message, but the trace it's self seems to only point at the error handler code
ReferenceError: user is not defined
at Server._handleError (/Users/mike/dev/ad/node_modules/adonis-framework/src/Server/index.js:108:11)
at co.catch (/Users/mike/dev/ad/node_modules/adonis-framework/src/Server/index.js:150:12)
at process._tickCallback (internal/process/next_tick.js:103:7)
This makes debugging very difficult. I don't know if this is a node or Adonis issue, (Sorry, I am new to nodeJS frameworks and have chosen Adonis based on years of Laravel use).
What does the code look like? Where exactly the user is undefined?
It was a mis-typed "use" statement.
But my question is more about the stack traces in general. Why are they not showing the same depth/level of stack trace as a typical node app? Can/will this be fixed?
I've hit these stacktraces a few times in the last few days. I'll post here an example whenever I hit it again…
For example, I have a middleware with this code:
class RestrictUnauthorized {
* handle (request, response, next) {
console.log(req.user)
yield next
}
}
module.exports = RestrictUnauthorized
Where req is not defined. So the error output would be:
ReferenceError: req is not defined
at Server._handleError (/Users/tema/Sites/ovelo-adonis/node_modules/adonis-framework/src/Server/index.js:108:11)
at co.catch (/Users/tema/Sites/ovelo-adonis/node_modules/adonis-framework/src/Server/index.js:150:12)
As we see, it is not possible to understand which file caused the error by looking on the stacktrace…
@SAGV Mind sharing the adonis-framework version from the package.json file.
@thetutlage it is 3.0.8
Mind updating to 3.0.9 and then re-try the same thing?
This commit https://github.com/adonisjs/adonis-framework/commit/90081facc85e654dbdc72c6042cbee832daeae67 fixed one of the known error stack issue.
Also error stack gets weird in Node.js, since at certain situations v8 does not return helpful stack traces and I believe everyone including and v8 are trying to come up with better outputs in the future
Yes, it is fixed now!
👍
@thetutlage I can confirm that 3.0.9 gives me the kind of stack trace I'd expect.
Thank you!
That is great! Happy endings. Closing the issue
Thank you ;-)
Am I able to re-open this @thetutlage ? It seems pointless to create a new issue.
When a 404 happens, the following trace is outputted to STDOUT
at Server._callRouteAction (/Users/mike/dev/appii-js/node_modules/adonis-framework/src/Server/index.js:73:13)
at finalHandler (/Users/mike/dev/appii-js/node_modules/adonis-framework/src/Server/index.js:212:18)
at finalHandler.next (<anonymous>)
at onFulfilled (/Users/mike/dev/appii-js/node_modules/co/index.js:65:19)
at /Users/mike/dev/appii-js/node_modules/co/index.js:54:5
at co (/Users/mike/dev/appii-js/node_modules/co/index.js:50:10)
at toPromise (/Users/mike/dev/appii-js/node_modules/co/index.js:118:63)
at next (/Users/mike/dev/appii-js/node_modules/co/index.js:99:29)
at onFulfilled (/Users/mike/dev/appii-js/node_modules/co/index.js:69:7)
(/Users/mike/dev/appii-js/node_modules/adonis-framework/src/Server/index.jsError
at Server._callRouteAction (/Users/mike/dev/appii-js/node_modules/adonis-framework/src/Server/index.js:73:13)
An exception is thrown with a suitable error message in Server/index.js:73, should this error message be output on the console?
This could also end up needlessly filling up logs if strack traces are printed to stdout in production, perhaps omitting the stack trace for simple things like 404 would be a solution?
You should edit the error handler method and instead of displaying the stack you should only display the message.
// app/Listeners/Http.js
console.error(error.message) // instead of error.stack
Oh, so it's up to me to configure this per application. That's great, thanks.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
That is great! Happy endings. Closing the issue