8000 Add support for Java stack traces (#1520) · PrismJS/prism@4a8219a · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 4a8219a

Browse files
RunDevelopmentmAAdhaTTah
authored andcommitted
Add support for Java stack traces (#1520)
There are 3 main types of elements which are highlighted: 1. The summary. This is the head of the stack trace and includes the name of the exception and a message. `Exception in thread "main" java.lang.RuntimeException: A test exception` 2. Stack frames. These make up the actual stack trace and include the full name of the method and the source. `at com.stackify.stacktrace.StackTraceExample.methodB(StackTraceExample.java:13)` 3. Omitted frames. This is a simple message that some frames were omitted. `... 27 more` Everything besides these 3 element types will not be highlighted.
1 parent a69c2b6 commit 4a8219a

10 files changed

+412
-3
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
@@ -382,6 +382,10 @@
382382
"require": "clike",
383383
"owner": "sherblot"
384384
},
385+
"javastacktrace": {
386+
"title": "Java stack trace",
387+
"owner": "RunDevelopment"
388+
},
385389
"jolie": {
386390
"title": "Jolie",
387391
"require": "clike",

components/prism-javastacktrace.js

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Prism.languages.javastacktrace = {
2+
3+
// java.sql.SQLException: Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...]
4+
// Caused by: java.sql.SQLException: Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...]
5+
// Caused by: com.example.myproject.MyProjectServletException
6+
// Caused by: MidLevelException: LowLevelException
7+
// Suppressed: Resource$CloseFailException: Resource ID = 0
8+
'summary': {
9+
pattern: /^[\t ]*(?:(?:Caused by:|Suppressed:|Exception in thread "[^"]*")[\t ]+)?[\w$.]+(?:\:.*)?$/m,
10+
inside: {
11+
'keyword': {
12+
pattern: /^(\s*)(?:(?:Caused by|Suppressed)(?=:)|Exception in thread)/m,
13+
lookbehind: true
14+
},
15+
16+
// the current thread if the summary starts with 'Exception in thread'
17+
'string': {
18+
pattern: /^(\s*)"[^"]*"/,
19+
lookbehind: true
20+
},
21+
'exceptions': {
22+
pattern: /^(:?\s*)[\w$.]+(?=:|$)/,
23+
lookbehind: true,
24+
inside: {
25+
'class-name': /[\w$]+(?=$|:)/,
26+
'namespace': /[a-z]\w*/,
27+
'punctuation': /[.:]/
28+
}
29+
},
30+
'message': {
31+
pattern: /(:\s*)\S.*/,
32+
lookbehind: true,
33+
alias: 'string'
34+
},
35+
'punctuation': /[:]/
36+
}
37+
},
38+
39+
// at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
40+
// at org.hsqldb.jdbc.Util.throwError(Unknown Source) here could be some notes
41+
// at Util.<init>(Unknown Source)
42+
'stack-frame': {
43+
pattern: /^[\t ]*at [\w$.]+(?:<init>)?\([^()]*\)/m,
44+
inside: {
45+
'keyword': {
46+
pattern: /^(\s*)at/,
47+
lookbehind: true
48+
},
49+
'source': [
50+
// (Main.java:15)
51+
// (Main.scala:15)
52+
{
53+
pattern: /(\()\w+.\w+:\d+(?=\))/,
54+
lookbehind: true,
55+
inside: {
56+
'file': /^\w+\.\w+/,
57+
'punctuation': /:/,
58+
'line-number': {
59+
pattern: /\d+/,
60+
alias: 'number'
61+
}
62+
}
63+
},
64+
// (Unknown Source)
65+
// (Native Method)
66+
// (...something...)
67+
{
68+
pattern: /(\()[^()]*(?=\))/,
69+
lookbehind: true,
70+
inside: {
71+
'keyword': /^(?:Unknown Source|Native Method)$/
72+
}
73+
}
74+
],
75+
'class-name': /[\w$]+(?=\.(?:<init>|[\w$]+)\()/,
76+
'function': /(?:<init>|[\w$]+)(?=\()/,
77+
'namespace': /[a-z]\w*/,
78+
'punctuation': /[.()]/
79+
}
80+
},
81+
82+
// ... 32 more
83+
// ... 32 common frames omitted
84+
'more': {
85+
pattern: /^[\t ]*\.{3} \d+ [a-z]+(?: [a-z]+)*/m,
86+
inside: {
87+
'punctuation': /\.{3}/,
88+
'number': /\d+/,
89+
'keyword': /\b[a-z]+(?: [a-z]+)*\b/
90+
}
91+
}
92+
93+
};

components/prism-javastacktrace.min.js

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

examples/prism-javastacktrace.html

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<h2>Full example</h2>
2+
<pre><code>javax.servlet.ServletException: Something bad happened
3+
at com.example.myproject.OpenSessionInViewFilter.doFilter(OpenSessionInViewFilter.java:60)
4+
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
5+
at com.example.myproject.ExceptionHandlerFilter.doFilter(ExceptionHandlerFilter.java:28)
6+
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
7+
at com.example.myproject.OutputBufferFilter.doFilter(OutputBufferFilter.java:33)
8+
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
9+
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
10+
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
11+
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
12+
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
13+
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
14+
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
15+
at org.mortbay.jetty.Server.handle(Server.java:326)
16+
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
17+
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)
18+
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
19+
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
20+
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
21+
at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
22+
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
23+
Caused by: com.example.myproject.MyProjectServletException
24+
at com.example.myproject.MyServlet.doPost(MyServlet.java:169)
25+
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
26+
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
27+
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
28+
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
29+
at com.example.myproject.OpenSessionInViewFilter.doFilter(OpenSessionInViewFilter.java:30)
30+
... 27 more
31+
Suppressed: org.hibernate.exception.ConstraintViolationException: could not insert: [com.example.myproject.MyEntity]
32+
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
33+
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
34+
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:64)
35+
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2329)
36+
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2822)
37+
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
38+
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
39+
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
40+
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
41+
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
42+
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
43+
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
44+
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
45+
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
46+
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
47+
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
48+
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
49+
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
50+
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
51+
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
52+
at java.lang.reflect.Method.invoke(Method.java:597)
53+
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344)
54+
at $Proxy19.save(Unknown Source)
55+
at com.example.myproject.MyEntityService.save(MyEntityService.java:59) &lt;-- relevant call (see notes below)
56+
at com.example.myproject.MyServlet.doPost(MyServlet.java:164)
57+
... 32 more
58+
Caused by: java.sql.SQLException: Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...]
59+
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
60+
at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
61+
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
62+
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:57)
63+
... 54 more</code></pre>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
1111
}
1212

1313
// The languages map is built automatically with gulp
14-
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC", 4E34 "csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;
14+
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC","csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javastacktrace":"Java stack trace","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;
1515
Prism.plugins.toolbar.registerButton('show-language', function(env) {
1616
var pre = env.element.parentNode;
1717
if (!pre || !/pre/i.test(pre.nodeName)) {

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,22 @@
1+
... 6 more
2+
... 6 common frames omitted
3+
4+
----------------------------------------------------
5+
6+
[
7+
["more", [
8+
["punctuation", "..."],
9+
["number", "6"],
10+
["keyword", "more"]
11+
]],
12+
13+
["more", [
14+
["punctuation", "..."],
15+
["number", "6"],
16+
["keyword", "common frames omitted"]
17+
]]
18+
]
19+
20+
----------------------------------------------------
21+
22+
Checks for the message that some frames were omitted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
at Main.main(Main.java:13)
2+
at Main.main(Main.java:13) Same but with some additional notes
3+
at com.foo.bar.Main$FooBar.main(Native Method)
4+
at Main$FooBar.<init>(Unknown Source)
5+
6+
----------------------------------------------------
7+
8+
[
9+
["stack-frame", [
10+
["keyword", "at"],
11+
["class-name", "Main"],
12+
["punctuation", "."],
13+
["function", "main"],
14+
["punctuation", "("],
15+
["source", [
16+
["file", "Main.java"],
17+
["punctuation", ":"],
18+
["line-number", "13"]
19+
]],
20+
["punctuation", ")"]
21+
]],
22+
23+
["stack-frame", [
24+
["keyword", "at"],
25+
["class-name", "Main"],
26+
["punctuation", "."],
27+
["function", "main"],
28+
["punctuation", "("],
29+
["source", [
30+
["file", "Main.java"],
31+
["punctuation", ":"],
32+
["line-number", "13"]
33+
]],
34+
["punctuation", ")"]
35+
]],
36+
" Same but with some additional notes\n",
37+
38+
["stack-frame", [
39+
["keyword", "at"],
40+
["namespace", "com"],
41+
["punctuation", "."],
42+
["namespace", "foo"],
43+
["punctuation", "."],
44+
["namespace", "bar"],
45+
["punctuation", "."],
46+
["class-name", "Main$FooBar"],
47+
["punctuation", "."],
48+
["function", "main"],
49+
["punctuation", "("],
50+
["source", [
51+
["keyword", "Native Method"]
52+
]],
53+
["punctuation", ")"]
54+
]],
55+
56+
["stack-frame", [
57+
["keyword", "at"],
58+
["class-name", "Main$FooBar"],
59+
["punctuation", "."],
60+
["function", "<init>"],
61+
["punctuation", "("],
62+
["source", [
63+
["keyword", "Unknown Source"]
64+
]],
65+
["punctuation", ")"]
66+
]]
67+
]
68+
69+
----------------------------------------------------
70+
71+
Checks for stack frames.

0 commit comments

Comments
 (0)
0