-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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]: TypeError encountered when logging class extending superclass which contains protected property #2103
Comments
@maverick1872 Can you get on this? |
On further consideration, I thought it was better to go forward with a patch-level reversion breaking any code that relied on the new functionality released just hours earlier than to be breaking what seemed likely to be a higher volume of previously working code on a feature update. |
I'm at the gym right now but I can definitely look into this. |
Successfully reproduced locally. Need to figure out how to get reproduced in a test environment but hoping to have a fix sorted out by Monday or so. |
@wbt @turchiad So finally got around back to doing some more diagnosing on this issue. The root cause of this TypeError is due to the fact that the This is something that will have to be considered to correctly apply metadata moving forward if we want to retain the mutating behavior of Winston. Working on a resolution that includes checks against the writable attribute of all properties. |
Have a fix in place for the TypeError, but this has brought to my attention another "side-effect" of the default metadata logic I introduced in I don't perceive this to be an issue (it appears to be a current behavior as well) though. Would love to publish an alpha version of the above fixes and maybe we can get some feedback on the metadata fixes prior to publishing a minor bump that will likely be consumed by default on package upgrades. |
What is the progress of this issue? I still can't use logger.child method to override defaultMeta. |
I too had to revert back to 3.7.1 so that I can still provide child loggers with override properties. Using 3.8.2 I did a test and found that if we change the child function to check for splats then we can preserve this issue fix as well as get back child override expected behaviour const hasSplats = !!info[Symbol.for('splat')];
// preserves non-writable props and assertions for user land
let infoClone;
if (hasSplats) {
// splats take precedence
infoClone = Object.assign(
defaultRequestMetadata,
info
);
} else {
// child meta takes precedence
infoClone = Object.assign(
info,
defaultRequestMetadata,
);
} This then produces log.info(new ThisError())
// output: {"canBeAnything":"","level":"info","message":"This must not be empty","service":"database-service"}
log.child({service: "child service", a: "child"}).info(new ThisError())
// output: {"a":"child","canBeAnything":"","level":"info","message":"This must not be empty","service":"child service"}
log.child({service: "child service", a: "child"}).info("", {service: "splat"})
// output: {"a":"child","level":"info","message":"","service":"splat"}
log.child({service: "child service", a: "child", canBeAnything: false}).info(new ThisError())
// output: Cannot assign to read only property 'canBeAnything' of object 'Error: This must not be empty' Im not that familiar with winston code. We may also need to merge in the splats data when they are present? |
Problem: Deprecated dependencies may not be noticed for a long time. npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. npm WARN deprecated winston@3.7.1: Please use version 3.6.0 or >3.7.1 when available due to winstonjs/winston#2103 Solution: Collect these warnings when running CI. TODO: fail if new warnings are found.
Problem: Deprecated dependencies may not be noticed for a long time. npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. npm WARN deprecated winston@3.7.1: Please use version 3.6.0 or >3.7.1 when available due to winstonjs/winston#2103 Solution: Collect these warnings when running CI. TODO: fail if new warnings are found.
Problem: Deprecated dependencies may not be noticed for a long time. npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. npm WARN deprecated winston@3.7.1: Please use version 3.6.0 or >3.7.1 when available due to winstonjs/winston#2103 Solution: Collect these warnings when running CI. TODO: fail if new warnings are found.
Problem: npm WARN deprecated winston@3.7.1: Please use version 3.6.0 or >3.7.1 when available due to winstonjs/winston#2103 Solution: Update winston.
🔎 Search Terms
TypeError
The problem
Regression in
winston
v3.7.1 caused the code shown further within to produce aTypeError
.See below error log:
What version of Winston presents the issue?
v3.7.1
What version of Node are you using?
v.17.8.0
If this worked in a previous version of Winston, which was it?
v3.6.0
Minimum Working Example
Additional information
This was encountered initially when using
winston
to report an error produced bymssql
.mssql
has their own error classes and whenwinston
upticked from v3.6.0 to v3.7.1 it broke our error reporting.Original code is closed source, but I have basically boiled down the minimum required to reproduce this error above.
Worth noting, perhaps, but
extend Error
is extra and I don't believe it's needed. Additionally, thisTypeError
is not reproduced ifthis.message
is omitted or is equal to''
.The text was updated successfully, but these errors were encountered: