3
3
* Licensed under the GNU Affero General Public License (AGPL).
4
4
* See License.AGPL.txt in the project root for license information.
5
5
*/
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
+
6
19
//@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" ) ;
10
23
11
24
const sourceMapCache = { } ;
12
25
@@ -27,10 +40,10 @@ async function fetchSourceMap(jsUrl) {
27
40
// Extract source map URL from the JS file
28
41
const mapUrlMatch = jsContent . match ( / \/ \/ # \s * s o u r c e M a p p i n g U R L = ( .+ ) / ) ;
29
42
if ( ! mapUrlMatch ) {
30
- throw new Error ( ' Source map URL not found' ) ;
43
+ throw new Error ( " Source map URL not found" ) ;
31
44
}
32
45
33
- const mapUrl = new URL ( mapUrlMatch [ 1 ] , jsUrl ) . href ; // Resolve relative URL
46
+ const mapUrl = new URL ( mapUrlMatch [ 1 ] , jsUrl ) . href ; // Resolve relative URL
34
47
const mapResponse = await fetch ( mapUrl ) ;
35
48
const mapData = await mapResponse . json ( ) ;
36
49
@@ -40,7 +53,7 @@ async function fetchSourceMap(jsUrl) {
40
53
return mapData ;
41
54
}
42
55
43
- const BASE_PATH = ' /workspace/gitpod/components' ;
56
+ const BASE_PATH = " /workspace/gitpod/components" ;
44
57
45
58
async function resolveLine ( line ) {
46
59
const jsUrl = extractJsUrlFromLine ( line ) ;
@@ -53,7 +66,7 @@ async function resolveLine(line) {
53
66
return line ;
54
67
}
55
68
56
- const functionName = matches [ 1 ] || '' ;
69
+ const functionName = matches [ 1 ] || "" ;
57
70
const lineNum = Number ( matches [ 3 ] ) ;
58
71
const colNum = Number ( matches [ 4 ] ) ;
59
72
@@ -69,18 +82,17 @@ async function resolveLine(line) {
69
82
return line ;
70
83
}
71
84
85
+ let obfuscatedTrace = "" ;
72
86
73
- let obfuscatedTrace = '' ;
74
-
75
- process . stdin . on ( 'data' , function ( data ) {
87
+ process . stdin . on ( "data" , function ( data ) {
76
88
obfuscatedTrace += data ;
77
89
} ) ;
78
90
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" ) ;
81
93
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" ) ;
84
96
console . log ( resolvedTrace ) ;
85
97
} ) ;
86
98
0 commit comments