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

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

Open
NazCodeland opened this issue Jan 10, 2023 · 3 comments
Open

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

NazCodeland opened this issue Jan 10, 2023 · 3 comments

Comments

@NazCodeland
Copy link

NazCodeland commented Jan 10, 2023

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
Copy link
Contributor

wbt commented Jan 12, 2023

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

@NazCodeland
Copy link
Author

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.

@tom-wild-moose
Copy link

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:

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

No branches or pull requests

3 participants