33 * Licensed under the GNU Affero General Public License (AGPL).
44 * See License.AGPL.txt in the project root for license information.
55 */
6+
7+ /*
8+ * Resolver allows to reconstruct stack traces from obfuscated stack traces for the dashboard.
9+ * Usage:
10+ * node resolver.js < obfuscated-stack-trace.txt
11+ *
12+ * OR
13+ *
14+ * node resolver.js <<EOF
15+ * obfuscated stack trace
16+ * EOF
17+ */
18+
619//@ts -check
7- const path = require ( ' path' ) ;
8- const fetch = require ( ' node-fetch' ) . default ;
9- const { SourceMapConsumer } = require ( ' source-map' ) ;
20+ const path = require ( " path" ) ;
21+ const fetch = require ( " node-fetch" ) . default ;
22+ const { SourceMapConsumer } = require ( " source-map" ) ;
1023
1124const sourceMapCache = { } ;
1225
@@ -27,10 +40,10 @@ async function fetchSourceMap(jsUrl) {
2740 // Extract source map URL from the JS file
2841 const mapUrlMatch = jsContent . match ( / \/ \/ # \s * s o u r c e M a p p i n g U R L = ( .+ ) / ) ;
2942 if ( ! mapUrlMatch ) {
30- throw new Error ( ' Source map URL not found' ) ;
43+ throw new Error ( " Source map URL not found" ) ;
3144 }
3245
33- const mapUrl = new URL ( mapUrlMatch [ 1 ] , jsUrl ) . href ; // Resolve relative URL
46+ const mapUrl = new URL ( mapUrlMatch [ 1 ] , jsUrl ) . href ; // Resolve relative URL
3447 const mapResponse = await fetch ( mapUrl ) ;
3548 const mapData = await mapResponse . json ( ) ;
3649
@@ -40,7 +53,7 @@ async function fetchSourceMap(jsUrl) {
4053 return mapData ;
4154}
4255
43- const BASE_PATH = ' /workspace/gitpod/components' ;
56+ const BASE_PATH = " /workspace/gitpod/components" ;
4457
4558async function resolveLine ( line ) {
4659 const jsUrl = extractJsUrlFromLine ( line ) ;
@@ -53,7 +66,7 @@ async function resolveLine(line) {
5366 return line ;
5467 }
5568
56- const functionName = matches [ 1 ] || '' ;
69+ const functionName = matches [ 1 ] || "" ;
5770 const lineNum = Number ( matches [ 3 ] ) ;
5871 const colNum = Number ( matches [ 4 ] ) ;
5972
@@ -69,18 +82,17 @@ async function resolveLine(line) {
6982 return line ;
7083}
7184
85+ let obfuscatedTrace = "" ;
7286
73- let obfuscatedTrace = '' ;
74-
75- process . stdin . on ( 'data' , function ( data ) {
87+ process . stdin . on ( "data" , function ( data ) {
7688 obfuscatedTrace += data ;
7789} ) ;
7890
79- process . stdin . on ( ' end' , async function ( ) {
80- const lines = obfuscatedTrace . split ( '\n' ) ;
91+ process . stdin . on ( " end" , async function ( ) {
92+ const lines = obfuscatedTrace . split ( "\n" ) ;
8193 const resolvedLines = await Promise . all ( lines . map ( resolveLine ) ) ;
82- const resolvedTrace = resolvedLines . join ( '\n' ) ;
83- console . log ( ' \nResolved Stack Trace:\n' ) ;
94+ const resolvedTrace = resolvedLines . join ( "\n" ) ;
95+ console . log ( " \nResolved Stack Trace:\n" ) ;
8496 console . log ( resolvedTrace ) ;
8597} ) ;
8698
0 commit comments