question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: TypeError encountered when logging class extending superclass which contains protected property

See original GitHub issue

🔎 Search Terms

TypeError

The problem

Regression in winston v3.7.1 caused the code shown further within to produce a TypeError.

See below error log:

      Object.assign(msg, this.defaultMeta, msgClone);
             ^

TypeError: Cannot assign to read only property 'canBeAnything' of object 'Error: This must not be empty'
    at Function.assign (<anonymous>)
    at DerivedLogger._addDefaultMeta (<PATH>/node_modules/winston/lib/winston/logger.js:639:14)
    at DerivedLogger.<computed> [as info] (<PATH>/node_modules/winston/lib/winston/create-logger.js:80:14)
    at Object.<anonymous> (<PATH>/index.js:31:5)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

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

const {createLogger, format, transports} = require('winston');
const {json} = format;

const log = createLogger({
	level: 'info',
	defaultMeta: {service: 'database-service'},
	transports: [
		new transports.Console({
			format: json(),
			level: 'info',
		}),
	]
});

class SuperError extends Error {
	constructor() {
		super();
		Object.defineProperty(this, 'canBeAnything', { enumerable: true, value: ''});
	}
}

class ThisError extends SuperError {
	message;

	constructor() {
		super();
		this.message = "This must not be empty";
	}
}

log.info(new ThisError());

Additional information

This was encountered initially when using winston to report an error produced by mssql. mssql has their own error classes and when winston 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, this TypeError is not reproduced if this.message is omitted or is equal to ''.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
maverick1872commented, Apr 8, 2022

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.

0reactions
WhiteMindscommented, Nov 16, 2022

What is the progress of this issue? I still can’t use logger.child method to override defaultMeta.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java: cannot access a protected member of the superclass in ...
Subclass is a class that extends another class. 2. Class members declared as protected can be accessed from the classes in the same...
Read more >
Private class features - JavaScript - MDN Web Docs - Mozilla
If you access a private property from an object that doesn't have the property, a TypeError is thrown, instead of returning undefined as ......
Read more >
Inheritance and Composition: A Python OOP Guide
Classes from which other classes are derived are called base classes or super classes. A derived class is said to derive, inherit, or...
Read more >
javascript class mixins - Durbuy tourisme
MixIns join a Class from the horizontal direction, but he is extending the ... has no fly() property, so it is returning an...
Read more >
dataclasses — Data Classes — Python 3.11.1 documentation
Source code: Lib/dataclasses.py This module provides a decorator and functions for automatically adding generated special method s such as__init__() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found