Skip to content
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

Error cause is not displayed #5630

Open
OliverJAsh opened this issue Apr 30, 2024 · 2 comments
Open

Error cause is not displayed #5630

OliverJAsh opened this issue Apr 30, 2024 · 2 comments

Comments

@OliverJAsh
Copy link

OliverJAsh commented Apr 30, 2024

package.json:

{
  "dependencies": {
    "express": "^4.19.2"
  }
}

server.js:

const express = require("express");

const app = express();

app.get("/", (req, res) => {
  throw new Error("foo", {
    cause: new Error("bar"),
  });
});

app.listen(3000, () => {
  console.log("Server is running on port 3000");
});
$ node server.js
Server is running on port 3000
$ curl "localhost:3000"

Actual

The error cause is not displayed.

Error: foo
    at /Users/oliver/Code/reduced-test-cases/express-error-cause/server.js:6:9
    at Layer.handle [as handle_request] (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/route.js:149:13)
    at Route.dispatch (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/route.js:119:3)
    at Layer.handle [as handle_request] (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/layer.js:95:5)
    at /Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/index.js:284:15
    at Function.process_params (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/index.js:346:12)
    at next (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/index.js:280:10)
    at expressInit (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/middleware/init.js:40:5)
    at Layer.handle [as handle_request] (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/layer.js:95:5)

Expected

The error cause should be displayed, like it is for exceptions occurring outside of request handlers.

Error: foo
    at /Users/oliver/Code/reduced-test-cases/express-error-cause/server.js:6:9
    at Layer.handle [as handle_request] (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/layer.js:95:5)
    ... 7 lines matching cause stack trace ...
    at Layer.handle [as handle_request] (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/layer.js:95:5) {
  [cause]: Error: bar
      at /Users/oliver/Code/reduced-test-cases/express-error-cause/server.js:7:12
      at Layer.handle [as handle_request] (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/layer.js:95:5)
      at next (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/route.js:149:13)
      at Route.dispatch (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/route.js:119:3)
      at Layer.handle [as handle_request] (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/layer.js:95:5)
      at /Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/index.js:284:15
      at Function.process_params (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/index.js:346:12)
      at next (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/index.js:280:10)
      at expressInit (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/middleware/init.js:40:5)
      at Layer.handle [as handle_request] (/Users/oliver/Code/reduced-test-cases/express-error-cause/node_modules/express/lib/router/layer.js:95:5)
}
@wesleytodd
Copy link
Member

Hey @OliverJAsh, thanks for the report. The specification for error causes is comparatively new to the code which handles this and the error stack is what we use for displaying this. I do agree though that showing error causes for development logging would be an awesome improvement. Feel free to open a PR for this one.

@shubham9069
Copy link

Hii @OliverJAsh thanks for the report. can you able to compile this enhancement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants