express icon indicating copy to clipboard operation
express copied to clipboard

Route logging on error

Open trexpert opened this issue 10 years ago • 4 comments

hi,

the route which is not valid should be logged with path. it's very hard to guess the invalid route.

lib/router/route.js [Line 195] var msg = 'Route.' + method + '() at path: "' +this.path+ '" requires callback functions but got a ' + type;

trexpert avatar Feb 29 '16 12:02 trexpert

@trexpert What does the error look like for you? I would expect the stack trace to indicate the script file and line number of the call that contains the problem.

tunniclm avatar Feb 29 '16 13:02 tunniclm

the part: *at path: "' +this.path+ '" *

is currently missing at the log message. i added this part. Would be nice to have the message on master

trexpert avatar Feb 29 '16 13:02 trexpert

Hi @trexpert, I believe the question was regarding what you are seeing with the existing master. We would expect that, in addition to the message, you are seeing a stack trace, which is pointing you to the file and line number in your code for where the problematic declaration is located. Can you paste here the error you are seeing on your console?

dougwilson avatar Mar 01 '16 03:03 dougwilson

@trexpert did you manage to resolve it?

You can actually see the path in question by doing this as you run your app:

DEBUG=express:router:route ./bin/www

More about debugging Express here.

Your stack trace will look something like this:

/my-app/node_modules/express/lib/router/route.js:196
        throw new Error(msg);
        ^

Error: Route.get() requires callback functions but got a [object Object]
    at Route.(anonymous function) [as get] (/my-app/node_modules/express/lib/router/route.js:196:15)
    at EventEmitter.app.(anonymous function) [as get] (/my-app/node_modules/express/lib/application.js:481:19)
    at Object.<anonymous> (/my-app/app.js:30:5)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/my-app/bin/www:7:11)

We can see that /my-app/app.js:30:5 is the last file and line in the code that I wrote, which had control over the execution of the program. So I would debug by tracing back from that point on.

In my case, I had specified a an object instead of a callback function for the path /hello in my app:

app.get('/hello', {});

Hope it helps.

hacksparrow avatar May 04 '16 17:05 hacksparrow