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

fix: Error cause is not displayed #49

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

DanielBelz1997
Copy link

@DanielBelz1997 DanielBelz1997 commented May 23, 2024

the 'cause' value in the Error class were not included in the response text.

This PR closes expressjs/express#5630

@UlisesGascon UlisesGascon changed the title fix: fixing express issue #5630 fix: Error cause is not displayed May 27, 2024
@UlisesGascon
Copy link
Member

UlisesGascon commented May 27, 2024

I enabled the CI runners :)

index.js Outdated
@@ -175,6 +180,11 @@ function getErrorMessage (err, status, env) {
// use err.stack, which typically includes err.message
msg = err.stack

// if error cause included
if (err.cause) {
msg += `\n[cause]: ${err.cause.stack}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The template literal strings are the cause of the CI failures. These are not supported in the older versions of node. Ideally we can just swap these for plain strings and then we can update them when we drop older node versions with the next major.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey! fixed it. i think that should work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I am gearing up for some travel, but I hope to loop back on this asap. Sorry things take so long sometimes, this is an entirely volunteer group so life and work usually come first. I promise we are working on it though.

Copy link
Member

@IamLizu IamLizu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your awesome contribution @DanielBelz1997 🥳

While I was reading your PR, I feel I need your help to understand the change. I would also like to request you to revert formatting changes.

var defer = typeof setImmediate === 'function'
? setImmediate
: function (fn) { process.nextTick(fn.bind.apply(fn, arguments)) }
var defer =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please revert the formatting change?

@@ -41,20 +44,22 @@ var isFinished = onFinished.isFinished
*/

function createHtmlDocument (message) {
var body = escapeHtml(message)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting help to understand, do we really need change this? Perhaps it is already handling multiple line error message?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just to chime in, this kind of thing is exactly why (as requested in @IamLizu's other comment) we try to avoid unnecessary formatting changes. It makes it harder to figure out what is a functional change needing attention and what is purely presentation and can be ignored.

@@ -175,6 +180,13 @@ function getErrorMessage (err, status, env) {
// use err.stack, which typically includes err.message
msg = err.stack

// if error cause included
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it handle nested cause? What if the cause itself has another cause? Also, perhaps it should append the stack trace of the error itself, regardless of whether the cause exists or not?

@@ -253,9 +265,7 @@ function getResponseStatusCode (res) {
*/

function headersSent (res) {
return typeof res.headersSent !== 'boolean'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert it, let's try to make less unwanted changes so its easier for the folks to review


request(server)
.get('/')
.expect(500, /[Error: bar]/, done)
Copy link

@coltonehrman coltonehrman Aug 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want to modify this test case a bit as it does not confirm the cause trace is printed anywhere.

I wrote a similar test case here I wrote a similar test case here if you want to use it https://github.com/coltonehrman/bag-of-tools/blob/main/examples/express/error-stack-trace/error.test.ts if you want to use some parts of it.

The test case I wrote confirms the existing functionality of it (ie: without the cause trace), and would need to be modified to include the cause trace somewhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you addressed this in your new PR, and since we haven't heard back from @DanielBelz1997 on reverting the formatting changes, I am considering closing this in favor of #50. @DanielBelz1997 opened theirs first, I want to give them a chance to fix this PR. I have some feedback I will leave on #50 as well, and if those are addressed first we will move forward with #50 instead of this one.

coltonehrman added a commit to coltonehrman/finalhandler that referenced this pull request Aug 11, 2024
This is a replacement for pillarjs#49.
I just pulled out the specific change related to this issue and added it here.

Closes: expressjs/express#5630
wesleytodd pushed a commit to coltonehrman/finalhandler that referenced this pull request Aug 31, 2024
This is a replacement for pillarjs#49.
I just pulled out the specific change related to this issue and added it here.

Closes: expressjs/express#5630

test: Error w/ cause case

fix: recursively find Error.cause stacks

Remove the error.stack logic as it is redundant

test: check for both 1 level & 2 level Error.cause

refactor: use native util.format() API for Error printing

fix: put back original lines of code

test: update tests to be less brittle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error cause is not displayed
5 participants