winstonjs/logform

[Bug]: Error formatter not working as shown in README example

NazCodeland opened this issue · 3 comments

The problem

I tried using the example shown in the README for the Error Format and I get this error:

module.exports = format((einfo, { stack }) => {
                                  ^

TypeError: Cannot destructure property 'stack' of 'undefined' as it is undefined.
    at Format.transform (C:\projectDirecotry\node_modules\logform\errors.js:14:35)
    at Object.<anonymous> (C:\projectDirectory\app.js:6:27)
    at Module._compile (node:internal/modules/cjs/loader:1205:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1259:10)
    at Module.load (node:internal/modules/cjs/loader:1068:32)
    at Module._load (node:internal/modules/cjs/loader:909:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:82:12)
    at node:internal/main/run_main_module:23:47

Node.js v19.1.0

What version of Logform presents the issue?

2.4.2

What version of Node are you using?

19.1.0

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

No response

Minimum Working Example

const { format } = require('logform');
const { errors } = format;

const errorsFormat = errors({ stack: true })

const info = errorsFormat.transform(new Error('Oh no!'));

console.log(info);
// Error: Oh no!
//     at repl:1:13
//     at ContextifyScript.Script.runInThisContext (vm.js:50:33)
//     at REPLServer.defaultEval (repl.js:240:29)
//     at bound (domain.js:301:14)
//     at REPLServer.runBound [as eval] (domain.js:314:12)
//     at REPLServer.onLine (repl.js:468:10)
//     at emitOne (events.js:121:20)
//     at REPLServer.emit (events.js:211:7)
//     at REPLServer.Interface._onLine (readline.js:282:10)
//     at REPLServer.Interface._line (readline.js:631:8)

Additional information

No response

🔎 Search Terms

Error Formatter

wbt commented

I'm a little confused here: does the comment show what you actually see? Is that different than what you expect?

The code block in "The problem" section is the error that I am getting when I try to run the code given for the Error Formatter in the README, which I copy and pasted in the "Minimum Working Example" section. Hope that answers your question.

Ran into the same issue.
We ended up having to pass the error object twice (as both "info" and "opts"), i.e. errorsFormat.transform(error, error).
Pretty bizarre, but seems to work: