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 format example throws TypeError #80

Open
jjdonov opened this issue Feb 7, 2019 · 3 comments
Open

Error format example throws TypeError #80

jjdonov opened this issue Feb 7, 2019 · 3 comments

Comments

@jjdonov
Copy link

jjdonov commented Feb 7, 2019

Hi there,

Trying to understand how I should be leveraging the Errors formatter in my own project. I tried following along with the example, but I get a TypeError. Is the example possibly out of date?

> const {format} = require('logform')
undefined
> const { errors } = format
undefined
> const fmt = errors({stack: true})
undefined
> const info = fmt.transform(new Error('oh no!'))
TypeError: Cannot destructure property `stack` of 'undefined' or 'null'.
    at Format.module.exports.format [as transform] (/Users/jjdonov/<omitted>/node_modules/logform/errors.js:14:25)
    at repl:1:18
    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:441:10)
    at emitOne (events.js:121:20)
    at REPLServer.emit (events.js:211:7)
    at REPLServer.Interface._onLine (readline.js:282:10)

I am using logform 2.1.2, included with winston 3.2.1

npm ls logform
<omitted>@0.0.0 <omitted>
└─┬ [email protected]
  └── [email protected]
@gurobokum
Copy link

transform method expects always to have 2 arguments that it passes internally. There is in winston repo. If you use fmt.transform manually you need to pass fmt.options

const fmt = errors({stack: true})
const info = fmt.transform(new Error('oh no!'), fmt.options);

@jjdonov
Copy link
Author

jjdonov commented Nov 6, 2019

Thanks @JIoJIaJIu
While that makes sense, I still think that the example in the documentation is misleading as it only passes one argument as I have above

@igoroctaviano
Copy link

Totally agree, https://github.com/winstonjs/logform#errors can't just follow the docs, same error.

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