winstonjs/logform

[Bug]: Custom Error objects seems to break error formatter

Sammaye opened this issue · 0 comments

The problem

I wrote this SO question: https://stackoverflow.com/questions/74294474/winston-format-errors-breaks-aws-error-logging

The more I debugged it the more it seemed to be the fact that AWS SDK responds with its own Error object, so I did a small hack like so:

            if (err instanceof Error) {
                // This is a workaround for errors that have custom
                // properties, like AWS SDK errors, they do not seem to work
                // with `Winston winston.format.errors({stack: true})` so
                // we copy the error object to a new fresh error object which seems to work
                const errc = new Error(err.message);
                errc.stack = err.stack;
                err = errc;
            }

Before I call Winston, and even though, yes it will just take standard errors and copy them it will also take custom ones and copy them and everything works great.

This seems very buggy to me since errors are literally getting lost and now I realise why my app is constantly getting bugs I cannot see errors for.

What version of Logform presents the issue?

v2.2.0

What version of Node are you using?

v16.14.2

If this worked in a previous version of Logform, which was it?

No response

Minimum Working Example

In order to replicate this I made a call to a S3 file that did not exist, but I am sure it is to do with any custom Error implementation.

Additional information

No response

🔎 Search Terms

winston breaks aws errors