Friday, 5 February 2021

Chromium console.error internal implementation - what makes hyperlinked path to files in error stack?

I noticed that error stack visible while using console.error has ability to make URIs hyperlinked. Such formatting takes place as well in browser Devtools as in IDE i use (WebStorm with integrated Git Bash terminal).

Example screen (this comes from Jest testing framework, but such hyperlinks are also provided in usual console.error calls):

enter image description here

As Node.js uses Chrome's V8 JS engine under the hood, i have tried to debug console.error internal implementation, but i hit the wall at this line of code - it uses stream to output the error message, which beforehand is just a string without any special formatting (except new lines) and afterwards becomes formatted output in console (including hyperlinks). I don't know what happens below there.

The Console.prototype.error method seems to be created by assigning Console.prototype.warn method to it, which is confusing. Also, Devtools console's inspect function won't navigate to the implementation of console methods while debugging Node.js, even despite the fact that Node's code is more accessible than the browser's one - i mean it's possible to debug Node's internals to some level, which is not a thing in the browser.

My question: is it possible to output hyperlinked content (my intention is to hyperlink path to a module) to the console output in a controllable way?

That question arised, because i am writing a Node.js wrapper on console methods i use in project and, as i had noticed the hyperlinks to files in call stacks, i wanted to use that feature inside my wrapper. I know there are libraries that wrap console and offer a ton of features, but i want to have a tiny wrapper, with just one or two features included. If somebody knows library that offers such controllable hyperlinking to the console output, i'd appreciate sharing a link, so i could look up for it's implementation.



from Chromium console.error internal implementation - what makes hyperlinked path to files in error stack?

No comments:

Post a Comment