Skip to content

fix(errors): default options so transform works without a second argument - #359

Open
sarathfrancis90 wants to merge 1 commit into
winstonjs:masterfrom
sarathfrancis90:fix-errors-format-missing-opts
Open

fix(errors): default options so transform works without a second argument#359
sarathfrancis90 wants to merge 1 commit into
winstonjs:masterfrom
sarathfrancis90:fix-errors-format-missing-opts

Conversation

@sarathfrancis90

Copy link
Copy Markdown

Fixes #238

The README's Errors example calls errorsFormat.transform(new Error('Oh no!')) with a single argument, but that throws TypeError: Cannot destructure property 'stack' of 'undefined'. Several people have hit this and worked around it by passing the error twice.

Cause: errors.js destructured its options parameter directly — (einfo, { stack, cause }) => ... — so when transform is called without a second argument, the destructure runs on undefined and throws.

Fix: default the options to an empty object and destructure stack/cause from it. This matches what timestamp, metadata and pretty-print already do, and is a no-op when options are passed normally through the format pipeline.

Testing: added a test that calls transform with a single argument (fails before, passes after). Full suite (170 tests) and lint are green.

…ment

The errors format destructured its options parameter directly
((einfo, { stack, cause }) => ...), so calling transform with only an
info argument threw 'Cannot destructure property stack of undefined'.
This is the exact call shown in the README's Errors example
(errorsFormat.transform(new Error('Oh no!'))).

Default the options to an empty object (as timestamp, metadata and
pretty-print already do) and destructure stack/cause from it.
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.

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

1 participant