Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign uplib: fix inspector links for stack traces #35725
Conversation
When the chrome inspector (chrome://inspect) display stack traces, it makes the filename clickable, and developer can easily locate the relevant source with a single click. This only works when filenames are valid URLs. The CJS loader seems to compile sources with absolute path instead of URL, breaking the inspector functionality. This is especially apparent when node_modules contain "at" symbol (@). The loader already presents module to the inspector using file URL, the same URL should be used for compiling the source.
|
Review requested: |
It seems getErrMessage() function uses filename from a CallSite to open a file and extract source code location of the statement. The CallSite now returns file URL, so it must be converted back to path.
Source maps seems to use CallSite from the prepareStackTrace to the path to the original sources on the stack. Finding the source map should convert file URL to path and attached information should be file URL instead of path, so the inspector can show a proper link. Additionally, it seems URL to path conversion was made by stripping "file://" prefix, which might cause problem on windows. The url module has function to deal with that.
Various tests explore the stack trace or CallSite objects' filename. They are modified now to match file URL instead.
Codecov Report
@@ Coverage Diff @@
## master #35725 +/- ##
==========================================
- Coverage 96.40% 96.40% -0.01%
==========================================
Files 222 223 +1
Lines 73682 73713 +31
==========================================
+ Hits 71034 71061 +27
- Misses 2648 2652 +4
Continue to review full report at Codecov.
|


When the chrome inspector (chrome://inspect) display stack traces, it
makes the filename clickable, and developer can easily locate the
relevant source with a single click. This only works when filenames are
valid URLs. The CJS loader seems to compile sources with absolute path
instead of URL, breaking the inspector functionality. This is especially
apparent when node_modules contain "at" symbol (@). The loader already
presents module to the inspector using file URL, the same URL should be
used for compiling the source.
For example the current stack trace looks like this:
and as shown the link covers only the part after the first slash after the
@directory. The link leads to URL starting with slash (/), which opens an empty (about:blank) tab within the browser. This is an expected behavior, because in URLs@representsuser@hostdelimiter and the path is not valid absolute URL as it does not have protocol. A properly fixed URL looks like this:and clicking on the link provided in inspector opens the actual location of the source for all call sites, including node_modules containing
@symbol in their path. For the console, the path is printed withfile://in front and clickable in some terminals.Note: (...) replaces a valid path omitted for security reasons.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes