Repository navigation
GROOVY-12732: log the text of an uncaught script exception, and print its trace once - #3267
Open
codeconsole wants to merge 3 commits into
Open
codeconsole wants to merge 3 commits into
codeconsole wants to merge 3 commits into
Conversation
… its trace once
GroovyMain.run() logged LOGGER.log(ERROR, "Caught: {0}", e). With a Throwable argument Java selects
System.Logger.log(Level, String, Throwable), so the placeholder was never filled and the logger printed the
full stack trace before StackTraceUtils.deepSanitize ran; printStackTrace() then printed the sanitized trace
a second time. The message is now "Caught: " + e, as before GROOVY-11886, and the trace is printed once,
sanitized unless -d is given.
… apostrophe
XStreamUtils.serialize logged LOGGER.log(WARNING, "Couldn''t write to " + name + ".xml", e). GROOVY-11886
doubled the quote for MessageFormat, but a message logged with a Throwable is not formatted, so the warning
read "Couldn''t write to ...". It is the same cause as the unfilled {0} in GroovyMain.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3267 +/- ##
==================================================
+ Coverage 74.4126% 74.4173% +0.0047%
- Complexity 44372 44379 +7
==================================================
Files 1699 1699
Lines 151051 151067 +16
Branches 28783 28790 +7
==================================================
+ Hits 112401 112420 +19
+ Misses 28376 28373 -3
Partials 10274 10274
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: bad60e6 Learn more about TestLens at testlens.app/docs. |
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://issues.apache.org/jira/browse/GROOVY-12732
When a script throws, the
groovycommand printedSEVERE: Caught: {0}and then the stack trace twice.GroovyMain.run()has calledLOGGER.log(ERROR, "Caught: {0}", e)since GROOVY-11886. Becauseeis aThrowable, Java selectsSystem.Logger.log(Level, String, Throwable)rather thanlog(Level, String, Object...), so the message is never formatted. The logger also printed the full stack trace beforeStackTraceUtils.deepSanitizeran, so that copy ignored-d.printStackTrace()then printed the sanitized trace a second time.The message is now
"Caught: " + e, the text the command printed before GROOVY-11886, and the trace is printed once byprintStackTrace(), sanitized unless-dis given.The same cause affected one other call. GROOVY-11886 doubled the apostrophe in
XStreamUtils.serialize's warning forMessageFormat,LOGGER.log(WARNING, "Couldn''t write to " + name + ".xml", e). That message is logged with itsThrowable, so it is not formatted either, and the warning readCouldn''t write to .... The second commit writes a plain apostrophe. Every other logging call with a{0}placeholder or a doubled quote passes arguments that are not throwables, soMessageFormatdoes format it. The third commit only shortens the comment from the first.Tests, each seen failing before its fix and passing after:
GroovyMainTest.testUncaughtExceptionIsLoggedWithItsTextAndItsStackTracePrintedOncecaptures thegroovy.ui.GroovyMainlog records. It checks for one SEVERE record whose formatted message isCaught: java.lang.IllegalStateException: boomand which carries no throwable, and for exactly one printed trace. On master it fails with'Caught: {0}'.XStreamUtilsTest.dumpThatCannotBeWrittenIsReportedWithItsCauseserializes into a directory that does not exist. It checks for one WARNING record whose formatted message isCouldn't write to <name>.xmland which carries theIOException../gradlew :test --tests 'groovy.ui.*' --tests 'org.codehaus.groovy.control.*'passes locally on JDK 21: 267 tests in 20 classes, 1 skipped (already@Disabled).The same lines are on
GROOVY_6_0_X, so this could be backported for 6.0.1.