-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
a69c2b6
commit 4a8219a
Showing
10 changed files
with
412 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
Prism.languages.javastacktrace = { | ||
|
||
// java.sql.SQLException: Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...] | ||
// Caused by: java.sql.SQLException: Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...] | ||
// Caused by: com.example.myproject.MyProjectServletException | ||
// Caused by: MidLevelException: LowLevelException | ||
// Suppressed: Resource$CloseFailException: Resource ID = 0 | ||
'summary': { | ||
pattern: /^[\t ]*(?:(?:Caused by:|Suppressed:|Exception in thread "[^"]*")[\t ]+)?[\w$.]+(?:\:.*)?$/m, | ||
inside: { | ||
'keyword': { | ||
pattern: /^(\s*)(?:(?:Caused by|Suppressed)(?=:)|Exception in thread)/m, | ||
lookbehind: true | ||
}, | ||
|
||
// the current thread if the summary starts with 'Exception in thread' | ||
'string': { | ||
pattern: /^(\s*)"[^"]*"/, | ||
lookbehind: true | ||
}, | ||
'exceptions': { | ||
pattern: /^(:?\s*)[\w$.]+(?=:|$)/, | ||
lookbehind: true, | ||
inside: { | ||
'class-name': /[\w$]+(?=$|:)/, | ||
'namespace': /[a-z]\w*/, | ||
'punctuation': /[.:]/ | ||
} | ||
}, | ||
'message': { | ||
pattern: /(:\s*)\S.*/, | ||
lookbehind: true, | ||
alias: 'string' | ||
}, | ||
'punctuation': /[:]/ | ||
} | ||
}, | ||
|
||
// at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) | ||
// at org.hsqldb.jdbc.Util.throwError(Unknown Source) here could be some notes | ||
// at Util.<init>(Unknown Source) | ||
'stack-frame': { | ||
pattern: /^[\t ]*at [\w$.]+(?:<init>)?\([^()]*\)/m, | ||
inside: { | ||
'keyword': { | ||
pattern: /^(\s*)at/, | ||
lookbehind: true | ||
}, | ||
'source': [ | ||
// (Main.java:15) | ||
// (Main.scala:15) | ||
{ | ||
pattern: /(\()\w+.\w+:\d+(?=\))/, | ||
lookbehind: true, | ||
inside: { | ||
'file': /^\w+\.\w+/, | ||
'punctuation': /:/, | ||
'line-number': { | ||
pattern: /\d+/, | ||
alias: 'number' | ||
} | ||
} | ||
}, | ||
// (Unknown Source) | ||
// (Native Method) | ||
// (...something...) | ||
{ | ||
pattern: /(\()[^()]*(?=\))/, | ||
lookbehind: true, | ||
inside: { | ||
'keyword': /^(?:Unknown Source|Native Method)$/ | ||
} | ||
} | ||
], | ||
'class-name': /[\w$]+(?=\.(?:<init>|[\w$]+)\()/, | ||
'function': /(?:<init>|[\w$]+)(?=\()/, | ||
'namespace': /[a-z]\w*/, | ||
'punctuation': /[.()]/ | ||
} | ||
}, | ||
|
||
// ... 32 more | ||
// ... 32 common frames omitted | ||
'more': { | ||
pattern: /^[\t ]*\.{3} \d+ [a-z]+(?: [a-z]+)*/m, | ||
inside: { | ||
'punctuation': /\.{3}/, | ||
'number': /\d+/, | ||
'keyword': /\b[a-z]+(?: [a-z]+)*\b/ | ||
} | ||
} | ||
|
||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<h2>Full example</h2> | ||
<pre><code>javax.servlet.ServletException: Something bad happened | ||
at com.example.myproject.OpenSessionInViewFilter.doFilter(OpenSessionInViewFilter.java:60) | ||
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) | ||
at com.example.myproject.ExceptionHandlerFilter.doFilter(ExceptionHandlerFilter.java:28) | ||
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) | ||
at com.example.myproject.OutputBufferFilter.doFilter(OutputBufferFilter.java:33) | ||
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) | ||
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) | ||
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) | ||
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) | ||
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) | ||
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) | ||
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) | ||
at org.mortbay.jetty.Server.handle(Server.java:326) | ||
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) | ||
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943) | ||
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756) | ||
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) | ||
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) | ||
at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228) | ||
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) | ||
Caused by: com.example.myproject.MyProjectServletException | ||
at com.example.myproject.MyServlet.doPost(MyServlet.java:169) | ||
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) | ||
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) | ||
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) | ||
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) | ||
at com.example.myproject.OpenSessionInViewFilter.doFilter(OpenSessionInViewFilter.java:30) | ||
... 27 more | ||
Suppressed: org.hibernate.exception.ConstraintViolationException: could not insert: [com.example.myproject.MyEntity] | ||
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96) | ||
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) | ||
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:64) | ||
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2329) | ||
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2822) | ||
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71) | ||
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268) | ||
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321) | ||
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204) | ||
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130) | ||
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210) | ||
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56) | ||
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195) | ||
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50) | ||
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93) | ||
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705) | ||
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693) | ||
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689) | ||
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source) | ||
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) | ||
at java.lang.reflect.Method.invoke(Method.java:597) | ||
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344) | ||
at $Proxy19.save(Unknown Source) | ||
at com.example.myproject.MyEntityService.save(MyEntityService.java:59) <-- relevant call (see notes below) | ||
at com.example.myproject.MyServlet.doPost(MyServlet.java:164) | ||
... 32 more | ||
Caused by: java.sql.SQLException: Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...] | ||
at org.hsqldb.jdbc.Util.throwError(Unknown Source) | ||
at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source) | ||
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105) | ||
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:57) | ||
... 54 more</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
... 6 more | ||
... 6 common frames omitted | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["more", [ | ||
["punctuation", "..."], | ||
["number", "6"], | ||
["keyword", "more"] | ||
]], | ||
|
||
["more", [ | ||
["punctuation", "..."], | ||
["number", "6"], | ||
["keyword", "common frames omitted"] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for the message that some frames were omitted. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
at Main.main(Main.java:13) | ||
at Main.main(Main.java:13) Same but with some additional notes | ||
at com.foo.bar.Main$FooBar.main(Native Method) | ||
at Main$FooBar.<init>(Unknown Source) | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["stack-frame", [ | ||
["keyword", "at"], | ||
["class-name", "Main"], | ||
["punctuation", "."], | ||
["function", "main"], | ||
["punctuation", "("], | ||
["source", [ | ||
["file", "Main.java"], | ||
["punctuation", ":"], | ||
["line-number", "13"] | ||
]], | ||
["punctuation", ")"] | ||
]], | ||
|
||
["stack-frame", [ | ||
["keyword", "at"], | ||
["class-name", "Main"], | ||
["punctuation", "."], | ||
["function", "main"], | ||
["punctuation", "("], | ||
["source", [ | ||
["file", "Main.java"], | ||
["punctuation", ":"], | ||
["line-number", "13"] | ||
]], | ||
["punctuation", ")"] | ||
]], | ||
" Same but with some additional notes\n", | ||
|
||
["stack-frame", [ | ||
["keyword", "at"], | ||
["namespace", "com"], | ||
["punctuation", "."], | ||
["namespace", "foo"], | ||
["punctuation", "."], | ||
["namespace", "bar"], | ||
["punctuation", "."], | ||
["class-name", "Main$FooBar"], | ||
["punctuation", "."], | ||
["function", "main"], | ||
["punctuation", "("], | ||
["source", [ | ||
["keyword", "Native Method"] | ||
]], | ||
["punctuation", ")"] | ||
]], | ||
|
||
["stack-frame", [ | ||
["keyword", "at"], | ||
["class-name", "Main$FooBar"], | ||
["punctuation", "."], | ||
["function", "<init>"], | ||
["punctuation", "("], | ||
["source", [ | ||
["keyword", "Unknown Source"] | ||
]], | ||
["punctuation", ")"] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for stack frames. |
Oops, something went wrong.