Skip to content

Commit

Permalink
Added JS stack trace language (#2418)
Browse files Browse the repository at this point in the history
This language highlights JavaScript stack traces generated by commonly used JS engines.
  • Loading branch information
sbrl authored Jun 22, 2020
1 parent 37273a6 commit ae0327b
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@
],
"owner": "RunDevelopment"
},
"jsstacktrace": {
"title": "JS stack trace",
"owner": "sbrl"
},
"js-templates": {
"title": "JS Templates",
"require": "javascript",
Expand Down
48 changes: 48 additions & 0 deletions components/prism-jsstacktrace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Prism.languages.jsstacktrace = {
'error-message': {
pattern: /^\S.*/m,
alias: 'string'
},

'stack-frame': {
pattern: /^[ \t]+at[ \t]+.*/m,
inside: {
'not-my-code': {
pattern: /[ \t]+at[ \t]+(?:node\.js|\<unknown\>|.*(?:node_modules|\(\<anonymous\>\)|\(\<unknown\>|\<anonymous\>$|\(internal\/|\(node\.js)).*/m,
alias: 'comment'
},

'filename': {
pattern: /(\bat\s+|\()(?:[a-zA-Z]:)?[^():]+(?=:)/,
lookbehind: true,
alias: 'url'
},

'function': {
pattern: /(at\s+(?:new\s+)?)[_$a-zA-Z\xA0-\uFFFF<][.$\w\xA0-\uFFFF<>]*/,
lookbehind: true,
inside: {
'punctuation': /\./
}
},

'punctuation': /[()]/,

'keyword': /\b(?:at|new)\b/,

'alias': {
pattern: /\[(?:as\s+)?[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*\]/,
alias: 'variable'
},

'line-number': {
pattern: /:[0-9]+(?::[0-9]+)?\b/,
alias: 'number',
inside: {
'punctuation': /:/
}
},

}
}
}
1 change: 1 addition & 0 deletions components/prism-jsstacktrace.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions examples/prism-jsstacktrace.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<h2>Full example</h2>
<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.
at Buffer (buffer.js:79:13)
at repl:1:1
at sigintHandlersWrap (vm.js:22:35)
at sigintHandlersWrap (vm.js:96:12)
at ContextifyScript.Script.runInThisContext (vm.js:21:12)
at REPLServer.defaultEval (repl.js:313:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.onLine (repl.js:513:10)
at emitOne (events.js:101:20)

Error: custom error
at Server.&lt;anonymous&gt; (/trace/showcases/http.js:4:9)
at emitTwo (events.js:106:13)
at Server.emit (events.js:191:7)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:543:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:105:23)
at new &lt;anonymous&gt; (_http_common.js:159:16)
at exports.FreeList.alloc (internal/freelist.js:14:46)
at Server.connectionListener (_http_server.js:316:24)
at emitOne (events.js:96:13)
at Server.emit (events.js:188:7)
at TCP.onconnection (net.js:1460:8)
at createServerHandle (net.js:1181:14)
at Server._listen2 (net.js:1225:14)
at listen (net.js:1290:10)
at Server.listen (net.js:1386:5)
at Object.&lt;anonymous&gt; (/trace/showcases/http.js:5:4)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (bootstrap_node.js:340:7)
at startup (bootstrap_node.js:132:9)
at bootstrap_node.js:455:3


Error: custom error
at /trace/showcases/basic.js:7:13
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
at InternalFieldObject.ondone (/trace/showcases/basic.js:6:13)
at /trace/showcases/basic.js:5:10
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:445:3)
at ReadFileContext.close (fs.js:358:11)
at FSReqWrap.readFileAfterRead [as oncomplete] (fs.js:414:15)
at ReadFileContext.read (fs.js:342:11)
at FSReqWrap.readFileAfterStat [as oncomplete] (fs.js:398:11)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:374:11)
at Object.fs.readFile (fs.js:303:11)
at Object.&lt;anonymous&gt; (/trace/showcases/basic.js:4:4)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (bootstrap_node.js:340:7)
at startup (bootstrap_node.js:132:9)
at bootstrap_node.js:455:3


BulkWriteError: E11000 duplicate key error collection: test.test index: _id_ dup key: { : 1 }
at OrderedBulkOperation.handleWriteError (/workspace/node_modules/mongodb/lib/bulk/common.js:1048:11)
at resultHandler (/workspace/node_modules/mongodb/lib/bulk/ordered.js:159:23)
at /workspace/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:532:18
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)

Error
at Collection.(anonymous function) [as insertMany] (/workspace/node_modules/monogram/lib/collection.js:80:21)
at insert (/workspace/test.js:14:31)
at run (/workspace/test.js:9:9)
at &lt;anonymous&gt;
at process._tickCallback (internal/process/next_tick.js:188:7)

Error
at Collection.(anonymous function) [as insertMany] (/workspace/node_modules/monogram/lib/collection.js:80:21)
at insert (/workspace/test.js:15:31)
at processTicksAndRejections (internal/process/next_tick.js:81:5)


Deno:

Error: Some error
at throwsA (&lt;unknown&gt;:1:23)
at &lt;unknown&gt;:1:13
at evaluate ($deno$/repl.ts:64:34)
at Object.replLoop ($deno$/repl.ts:153:13)

Uncaught NotFound: No such file or directory (os error 2)
at DenoError (deno/js/errors.ts:22:5)
at maybeError (deno/js/errors.ts:41:12)
at handleAsyncMsgFromRust (deno/js/dispatch.ts:27:17)
</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"jq": "JQ",
"jsdoc": "JSDoc",
"js-extras": "JS Extras",
"jsstacktrace": "JS stack trace",
"js-templates": "JS Templates",
"json": "JSON",
"webmanifest": "Web App Manifest",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/languages/jsstacktrace/errormessage-nodejs_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(node:16843) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'tick' of undefined

----------------------------------------------------

[
["error-message", "(node:16843) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'tick' of undefined"]
]

----------------------------------------------------

Checks basic a basic error message.
11 changes: 11 additions & 0 deletions tests/languages/jsstacktrace/errormessage_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Some text

----------------------------------------------------

[
["error-message", "Some text"]
]

----------------------------------------------------

Checks basic a basic error message.
30 changes: 30 additions & 0 deletions tests/languages/jsstacktrace/filename_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Some text
at (foo/bar.baz:123:98)

----------------------------------------------------

[
["error-message", "Some text"],
[
"stack-frame",
[
["keyword", "at"],
["punctuation", "("],
["filename", "foo/bar.baz"],
[
"line-number",
[
["punctuation", ":"],
"123",
["punctuation", ":"],
"98"
]
],
["punctuation", ")"]
]
]
]

----------------------------------------------------

Checks basic a basic error message.
28 changes: 28 additions & 0 deletions tests/languages/jsstacktrace/filenamedirect_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Some text
at /foo/bar.baz:123:98

----------------------------------------------------

[
["error-message", "Some text"],
[
"stack-frame",
[
["keyword", "at"],
["filename", "/foo/bar.baz"],
[
"line-number",
[
["punctuation", ":"],
"123",
["punctuation", ":"],
"98"
]
]
]
]
]

----------------------------------------------------

Checks basic a basic error message.
28 changes: 28 additions & 0 deletions tests/languages/jsstacktrace/filenamedirectwindows_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Some text
at C:\foo\bar.baz:123:98

----------------------------------------------------

[
["error-message", "Some text"],
[
"stack-frame",
[
["keyword", "at"],
["filename", "C:\\foo\\bar.baz"],
[
"line-number",
[
["punctuation", ":"],
"123",
["punctuation", ":"],
"98"
]
]
]
]
]

----------------------------------------------------

Checks basic a basic error message.
26 changes: 26 additions & 0 deletions tests/languages/jsstacktrace/function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Some text
at foo.bar

----------------------------------------------------

[
["error-message", "Some text"],
[
"stack-frame",
[
["keyword", "at"],
[
"function",
[
"foo",
[ "punctuation", "." ],
"bar"
]
]
]
]
]

----------------------------------------------------

Checks basic a basic error message.
29 changes: 29 additions & 0 deletions tests/languages/jsstacktrace/linenumber_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Some text
at :98:32

----------------------------------------------------

[
["error-message", "Some text"],
[
"stack-frame", [
[
"keyword",
"at"
],
[
"line-number",
[
["punctuation", ":"],
"98",
["punctuation", ":"],
"32"
]
]
]
]
]

----------------------------------------------------

Checks basic a basic error message.
18 changes: 18 additions & 0 deletions tests/languages/jsstacktrace/notmycode_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Some text
at processTicksAndRejections (internal/process/task_queues.js:98:32)

----------------------------------------------------

[
["error-message", "Some text"],
[
"stack-frame",
[
["not-my-code", "\tat processTicksAndRejections (internal/process/task_queues.js:98:32)"]
]
]
]

----------------------------------------------------

Checks greying out internal / library code stack trace frames

0 comments on commit ae0327b

Please sign in to comment.