Open raducoravu opened 3 years ago
Looking at the Java code for org.apache.tools.ant.launch.Launcher.main(String[]) it logs all fatal exceptions to System.err:
} catch (final Throwable t) {
exitCode = EXIT_CODE_ERROR;
t.printStackTrace(System.err); //NOSONAR
}
The org.dita.dost.invoker.Main somehow changes the System.err in a way in which these exception stack traces no longer make it to the console output.
The Laucher class is an Ant class that we haven't forked and I would prefer us not to fork it. The Main class does revert to the original System.err, see https://github.com/dita-ot/dita-ot/blob/develop/src/main/java/org/dita/dost/invoker/Main.java#L684.
I haven't encountered this issue before. Does this happen if you just use -v
, not -d
. We could throw an error if you have both, because they override each other.
Attaching a sample project.
I run the DITA OT 3.6 from the command line like this:
sh dita -i /Users/raducoravu/Desktop/wrongURI/test.ditamap -f html5 -v
and I do not get the exception stack trace. Same if I'm running it with "-d", I only get in the console this part of the error:
Error: java.lang.RuntimeException: Expected scheme-specific part at index 5: http:
but not the entire stack trace of the error.
Found a similar problem today, we run the DITA OT with a restricted security manager, it breaks the entire processing with a PrivilegedActionException and we cannot see the stack trace when running with the "dita" command, even if the "-d" flag is set.
This kind of problem affects also the DITA OT developers, because if someone encounters an exception when running from the command line, they cannot obtain and post the entire stack trace of the exception.
@jelovirt can you reproduce the problem with my samples?
Using DITA-OT 3.7.3, I seem to have this problem too.
@jelovirt maybe you can help me a bit, the problem with the dita.bat not showing error stack traces is here: org.dita.dost.invoker.DefaultLogger.throwableMessage(StringBuilder, Throwable, boolean) as compared with the default logger implementation in ANT which prints the stack trace: org.apache.tools.ant.DefaultLogger.throwableMessage(StringBuffer, Throwable, boolean)
but I do not understand the reason for the changes. I think showing an exception stack trace in the console when using -v is important as users may be able to add the stack trace on the issues they open. So I think we should add exception stack traces to the console output when -v is used.
@raducoravu I'm not sure how to add an exception for stacktraces 🤔
The ANT logger org.apache.tools.ant.DefaultLogger.throwableMessage(StringBuffer, Throwable, boolean) adds it something like this:
if (verbose || !(error instanceof BuildException)) {
m.append(StringUtils.getStackTrace(error));
}
I have a small DITA Map with a single topic containing a link like the one in #3730
I publish to HTML5 from the command line using the "-v" flag:
the console does not have the entire stack trace of the error inside it:
If I run the publishing without using the "dita" command, just by using the ANT jar libraries, the stack trace is fully included in the console output: