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

fix: avoid override mistake #1939

Merged
merged 3 commits into from
Apr 5, 2024

Conversation

erights
Copy link
Contributor

@erights erights commented Apr 3, 2024

The assignment at this location was to a self object that inherits from the console (or what was the console before this code ran). This assignment was use to override properties typically inherited from console such as error,warn,info,debug,trace. However, if the console object it inherits from is frozen, as it is in the ses-shim of HardenedJS, then this assignment fails due to the so-called "override mistake".

Changing this assignment to use Object.defineProperty instead avoids hitting the override mistake. The additional attributes I include in this change

    writable: true,
    enumerable: true,
    configurable: true,

are only there to preserve equivalence with assignment. But feel free to change them to whatever you'd like. Such changes would not affect the purpose of this PR.

@mcollina
Copy link
Member

mcollina commented Apr 3, 2024

Can you add a test?

@erights
Copy link
Contributor Author

erights commented Apr 4, 2024

Done. The added test/browser-early-console-freeze.test.js succeeds with this PR. Without this PR it fails as follows:

test/browser-early-console-freeze.test.js 2> /Users/markmiller/src/ongithub/erights/pino/browser.js:9
test/browser-early-console-freeze.test.js 2> 
self[level]=levelToValue(self.level,rootLogger)>levelToValue(level,rootLogger)?(cov_qeewo7tvl().b[37][0]++,noop):(cov_qeewo7tvl().b[37][1]++,rootLogger[baseLogFunctionSymbol][level]);cov_qeewo7tvl().s[117]++;if(
(cov_qeewo7tvl().b[39][0]++,!opts.transmit)&&(cov_qeewo7tvl().b[39][1]++,self[level]===noop)){cov_qeewo7tvl().b[38][0]++;cov_qeewo7tvl().s[118]++;return;}else{cov_qeewo7tvl().b[38][1]++;}// make sure the log
format is correct
test/browser-early-console-freeze.test.js 2>            ^
test/browser-early-console-freeze.test.js 2> 
test/browser-early-console-freeze.test.js 2> TypeError: Cannot assign to read only property 'error' of object '#<Object>'
test/browser-early-console-freeze.test.js 2>     at set (/Users/markmiller/src/ongithub/erights/pino/browser.js:9:12)
test/browser-early-console-freeze.test.js 2>     at console.setLevel (/Users/markmiller/src/ongithub/erights/pino/browser.js:3:1735)
test/browser-early-console-freeze.test.js 2>     at pino (/Users/markmiller/src/ongithub/erights/pino/browser.js:3:483)
test/browser-early-console-freeze.test.js 2>     at Test.<anonymous> (/Users/markmiller/src/ongithub/erights/pino/test/browser-early-console-freeze.test.js:7:3)
test/browser-early-console-freeze.test.js 2>     at Test.run (/Users/markmiller/src/ongithub/erights/pino/node_modules/tape/lib/test.js:127:28)
test/browser-early-console-freeze.test.js 2>     at Immediate.next (/Users/markmiller/src/ongithub/erights/pino/node_modules/tape/lib/results.js:156:7)
test/browser-early-console-freeze.test.js 2>     at process.processImmediate (node:internal/timers:476:21)
test/browser-early-console-freeze.test.js 2> 
test/browser-early-console-freeze.test.js 2> Node.js v18.19.0
​ FAIL ​ TAP
 ✖ test/browser-early-console-freeze.test.js

@erights
Copy link
Contributor Author

erights commented Apr 4, 2024

The

TypeError: Cannot assign to read only property 'error' of object

is exactly the symptom we saw in our own system that led us here.

@kriskowal
Copy link

@mcollina Thanks for considering this change.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@kriskowal
Copy link

There’s a test failure affecting only Windows. Can I trouble a maintainer to re-run that to verify whether this is a flake?

@jsumners
Copy link
Member

jsumners commented Apr 5, 2024

It's the transport tests. I wish I knew why they consistently fail as often as they do. But we can just ignore it for this.

@mcollina mcollina merged commit 9c39e0f into pinojs:master Apr 5, 2024
20 of 21 checks passed
@erights
Copy link
Contributor Author

erights commented Apr 5, 2024

Thanks!

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.

4 participants