Skip to content

Commit ae0327b

Browse files
authored
Added JS stack trace language (#2418)
This language highlights JavaScript stack traces generated by commonly used JS engines.
1 parent 37273a6 commit ae0327b

15 files changed

+336
-2
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,10 @@
548548
],
549549
"owner": "RunDevelopment"
550550
},
551+
"jsstacktrace": {
552+
"title": "JS stack trace",
553+
"owner": "sbrl"
554+
},
551555
"js-templates": {
552556
"title": "JS Templates",
553557
"require": "javascript",

components/prism-jsstacktrace.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Prism.languages.jsstacktrace = {
2+
'error-message': {
3+
pattern: /^\S.*/m,
4+
alias: 'string'
5+
},
6+
7+
'stack-frame': {
8+
pattern: /^[ \t]+at[ \t]+.*/m,
9+
inside: {
10+
'not-my-code': {
11+
pattern: /[ \t]+at[ \t]+(?:node\.js|\<unknown\>|.*(?:node_modules|\(\<anonymous\>\)|\(\<unknown\>|\<anonymous\>$|\(internal\/|\(node\.js)).*/m,
12+
alias: 'comment'
13+
},
14+
15+
'filename': {
16+
pattern: /(\bat\s+|\()(?:[a-zA-Z]:)?[^():]+(?=:)/,
17+
lookbehind: true,
18+
alias: 'url'
19+
},
20+
21+
'function': {
22+
pattern: /(at\s+(?:new\s+)?)[_$a-zA-Z\xA0-\uFFFF<][.$\w\xA0-\uFFFF<>]*/,
23+
lookbehind: true,
24+
inside: {
25+
'punctuation': /\./
26+
}
27+
},
28+
29+
'punctuation': /[()]/,
30+
31+
'keyword': /\b(?:at|new)\b/,
32+
33+
'alias': {
34+
pattern: /\[(?:as\s+)?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\]/,
35+
alias: 'variable'
36+
},
37+
38+
'line-number': {
39+
pattern: /:[0-9]+(?::[0-9]+)?\b/,
40+
alias: 'number',
41+
inside: {
42+
'punctuation': /:/
43+
}
44+
},
45+
46+
}
47+
}
48+
}

components/prism-jsstacktrace.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-jsstacktrace.html

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<h2>Full example</h2>
2+
<pre><code>(node:40780) DeprecationWarning: Using Buffer without `new` will soon stop working. Use `new Buffer()`, or preferably `Buffer.from()`, `Buffer.allocUnsafe()` or `Buffer.alloc()` instead.
3+
at Buffer (buffer.js:79:13)
4+
at repl:1:1
5+
at sigintHandlersWrap (vm.js:22:35)
6+
at sigintHandlersWrap (vm.js:96:12)
7+
at ContextifyScript.Script.runInThisContext (vm.js:21:12)
8+
at REPLServer.defaultEval (repl.js:313:29)
9+
at bound (domain.js:280:14)
10+
at REPLServer.runBound [as eval] (domain.js:293:12)
11+
at REPLServer.onLine (repl.js:513:10)
12+
at emitOne (events.js:101:20)
13+
14+
Error: custom error
15+
at Server.&lt;anonymous&gt; (/trace/showcases/http.js:4:9)
16+
at emitTwo (events.js:106:13)
17+
at Server.emit (events.js:191:7)
18+
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:543:12)
19+
at HTTPParser.parserOnHeadersComplete (_http_common.js:105:23)
20+
at new &lt;anonymous&gt; (_http_common.js:159:16)
21+
at exports.FreeList.alloc (internal/freelist.js:14:46)
22+
at Server.connectionListener (_http_server.js:316:24)
23+
at emitOne (events.js:96:13)
24+
at Server.emit (events.js:188:7)
25+
at TCP.onconnection (net.js:1460:8)
26+
at createServerHandle (net.js:1181:14)
27+
at Server._listen2 (net.js:1225:14)
28+
at listen (net.js:1290:10)
29+
at Server.listen (net.js:1386:5)
30+
at Object.&lt;anonymous&gt; (/trace/showcases/http.js:5:4)
31+
at Module._compile (module.js:541:32)
32+
at Object.Module._extensions..js (module.js:550:10)
33+
at Module.load (module.js:458:32)
34+
at tryModuleLoad (module.js:417:12)
35+
at Function.Module._load (module.js:409:3)
36+
at Module.runMain (module.js:575:10)
37+
at run (bootstrap_node.js:340:7)
38+
at startup (bootstrap_node.js:132:9)
39+
at bootstrap_node.js:455:3
40+
41+
42+
Error: custom error
43+
at /trace/showcases/basic.js:7:13
44+
at _combinedTickCallback (internal/process/next_tick.js:67:7)
45+
at process._tickCallback (internal/process/next_tick.js:98:9)
46+
at InternalFieldObject.ondone (/trace/showcases/basic.js:6:13)
47+
at /trace/showcases/basic.js:5:10
48+
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3)
49+
at ReadFileContext.close (fs.js:358:11)
50+
at FSReqWrap.readFileAfterRead [as oncomplete] (fs.js:414:15)
51+
at ReadFileContext.read (fs.js:342:11)
52+
at FSReqWrap.readFileAfterStat [as oncomplete] (fs.js:398:11)
53+
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:374:11)
54+
at Object.fs.readFile (fs.js:303:11)
55+
at Object.&lt;anonymous&gt; (/trace/showcases/basic.js:4:4)
56+
at Module._compile (module.js:541:32)
57+
at Object.Module._extensions..js (module.js:550:10)
58+
at Module.load (module.js:458:32)
59+
at tryModuleLoad (module.js:417:12)
60+
at Function.Module._load (module.js:409:3)
61+
at Module.runMain (module.js:575:10)
62+
at run (bootstrap_node.js:340:7)
63+
at startup (bootstrap_node.js:132:9)
64+
at bootstrap_node.js:455:3
65+
66+
67+
BulkWriteError: E11000 duplicate key error collection: test.test index: _id_ dup key: { : 1 }
68+
at OrderedBulkOperation.handleWriteError (/workspace/node_modules/mongodb/lib/bulk/common.js:1048:11)
69+
at resultHandler (/workspace/node_modules/mongodb/lib/bulk/ordered.js:159:23)
70+
at /workspace/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:532:18
71+
at _combinedTickCallback (internal/process/next_tick.js:131:7)
72+
at process._tickCallback (internal/process/next_tick.js:180:9)
73+
74+
Error
75+
at Collection.(anonymous function) [as insertMany] (/workspace/node_modules/monogram/lib/collection.js:80:21)
76+
at insert (/workspace/test.js:14:31)
77+
at run (/workspace/test.js:9:9)
78+
at &lt;anonymous&gt;
79+
at process._tickCallback (internal/process/next_tick.js:188:7)
80+
81+
Error
82+
at Collection.(anonymous function) [as insertMany] (/workspace/node_modules/monogram/lib/collection.js:80:21)
83+
at insert (/workspace/test.js:15:31)
84+
at processTicksAndRejections (internal/process/next_tick.js:81:5)
85+
86+
87+
Deno:
88+
89+
Error: Some error
90+
at throwsA (&lt;unknown&gt;:1:23)
91+
at &lt;unknown&gt;:1:13
92+
at evaluate ($deno$/repl.ts:64:34)
93+
at Object.replLoop ($deno$/repl.ts:153:13)
94+
95+
Uncaught NotFound: No such file or directory (os error 2)
96+
at DenoError (deno/js/errors.ts:22:5)
97+
at maybeError (deno/js/errors.ts:41:12)
98+
at handleAsyncMsgFromRust (deno/js/dispatch.ts:27:17)
99+
</code></pre>

plugins/show-language/prism-show-language.js

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"jq": "JQ",
8989
"jsdoc": "JSDoc",
9090
"js-extras": "JS Extras",
91+
"jsstacktrace": "JS stack trace",
9192
"js-templates": "JS Templates",
9293
"json": "JSON",
9394
"webmanifest": "Web App Manifest",

plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(node:16843) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'tick' of undefined
2+
3+
----------------------------------------------------
4+
5+
[
6+
["error-message", "(node:16843) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'tick' of undefined"]
7+
]
8+
9+
----------------------------------------------------
10+
11+
Checks basic a basic error message.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Some text
2+
3+
----------------------------------------------------
4+
5+
[
6+
["error-message", "Some text"]
7+
]
8+
9+
----------------------------------------------------
10+
11+
Checks basic a basic error message.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Some text
2+
at (foo/bar.baz:123:98)
3+
4+
----------------------------------------------------
5+
6+
[
7+
["error-message", "Some text"],
8+
[
9+
"stack-frame",
10+
[
11+
["keyword", "at"],
12+
["punctuation", "("],
13+
["filename", "foo/bar.baz"],
14+
[
15+
"line-number",
16+
[
17+
["punctuation", ":"],
18+
"123",
19+
["punctuation", ":"],
20+
"98"
21+
]
22+
],
23+
["punctuation", ")"]
24+
]
25+
]
26+
]
27+
28+
----------------------------------------------------
29+
30+
Checks basic a basic error message.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Some text
2+
at /foo/bar.baz:123:98
3+
4+
----------------------------------------------------
5+
6+
[
7+
["error-message", "Some text"],
8+
[
9+
"stack-frame",
10+
[
11+
["keyword", "at"],
12+
["filename", "/foo/bar.baz"],
13+
[
14+
"line-number",
15+
[
16+
["punctuation", ":"],
17+
"123",
18+
["punctuation", ":"],
19+
"98"
20+
]
21+
]
22+
]
23+
]
24+
]
25+
26+
----------------------------------------------------
27+
28+
Checks basic a basic error message.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Some text
2+
at C:\foo\bar.baz:123:98
3+
4+
----------------------------------------------------
5+
6+
[
7+
["error-message", "Some text"],
8+
[
9+
"stack-frame",
10+
[
11+
["keyword", "at"],
12+
["filename", "C:\\foo\\bar.baz"],
13+
[
14+
"line-number",
15+
[
16+
["punctuation", ":"],
17+
"123",
18+
["punctuation", ":"],
19+
"98"
20+
]
21+
]
22+
]
23+
]
24+
]
25+
26+
----------------------------------------------------
27+
28+
Checks basic a basic error message.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Some text
2+
at foo.bar
3+
4+
----------------------------------------------------
5+
6+
[
7+
["error-message", "Some text"],
8+
[
9+
"stack-frame",
10+
[
11+
["keyword", "at"],
12+
[
13+
"function",
14+
[
15+
"foo",
16+
[ "punctuation", "." ],
17+
"bar"
18+
]
19+
]
20+
]
21+
]
22+
]
23+
24+
----------------------------------------------------
25+
26+
Checks basic a basic error message.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Some text
2+
at :98:32
3+
4+
----------------------------------------------------
5+
6+
[
7+
["error-message", "Some text"],
8+
[
9+
"stack-frame", [
10+
[
11+
"keyword",
12+
"at"
13+
],
14+
[
15+
"line-number",
16+
[
17+
["punctuation", ":"],
18+
"98",
19+
["punctuation", ":"],
20+
"32"
21+
]
22+
]
23+
]
24+
]
25+
]
26+
27+
----------------------------------------------------
28+
29+
Checks basic a basic error message.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Some text
2+
at processTicksAndRejections (internal/process/task_queues.js:98:32)
3+
4+
----------------------------------------------------
5+
6+
[
7+
["error-message", "Some text"],
8+
[
9+
"stack-frame",
10+
[
11+
["not-my-code", "\tat processTicksAndRejections (internal/process/task_queues.js:98:32)"]
12+
]
13+
]
14+
]
15+
16+
----------------------------------------------------
17+
18+
Checks greying out internal / library code stack trace frames

0 commit comments

Comments
 (0)