Repository navigation
fix: preserve Error stack with splat format args - #2649
Open
SahinurDEV wants to merge 1 commit into
Open
SahinurDEV wants to merge 1 commit into
SahinurDEV wants to merge 1 commit into
Conversation
logform's splat format Object.assigns leftover metas onto info, but
Error.message/stack/cause are non-enumerable so the stack was dropped
for calls like logger.error('Oops %d', 1, err). Normalize Error splat
args so stack and cause are enumerable without overwriting the
formatted message.
Fixes winstonjs#2527
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
logger.error('Oops', err)correctly logs the error stack, butlogger.error('Oops %d', 1, err)drops the Error entirely — no stackreaches
printf/jsonformatters.Cause
logform's splat format
Object.assigns leftover metas ontoinfo.Error.message/Error.stack/Error.causeare non-enumerable, sothe leftover Error after format tokens contributed nothing.
Fix
In
Logger#log, normalize Error values in the splat array sostackand
causebecome enumerable own properties before they reach splat.messageis intentionally not copied, so the already-formatted logmessage is not overwritten.
Tests
Added a unit test that logs
error('Oops %d', 1, err)withformat.errors({ stack: true })+format.splat()and assertsinfo.stackis preserved.Fixes #2527