dita-ot / dita-ot

DITA Open Toolkit — the open-source publishing engine for content authored in the Darwin Information Typing Architecture.
https://www.dita-ot.org
Apache License 2.0
404 stars 196 forks source link

Running the dita command sometimes does not show the entire error stack trace #3731

Open raducoravu opened 3 years ago

raducoravu commented 3 years ago

I have a small DITA Map with a single topic containing a link like the one in #3730

<xref href="http://www,oxygenxml.com" format="html" scope="external"/>

I publish to HTML5 from the command line using the "-v" flag:

 dita -i D:\projects\flowers\flowers.ditamap -f html5 -v -d

the console does not have the entire stack trace of the error inside it:

   [antcall] Exiting d:\projects\eXml\frameworks\dita\DITA-OT3.x\build.xml.
    Error: java.lang.RuntimeException: Expected scheme-specific part at index 5: http:

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:

D:\projects\DITA-OT3.x\plugins\org.dita.base\build_preprocess.xml:96: java.lang.RuntimeException: Expected scheme-specific part at index 5: http:
at org.dita.dost.util.URLUtils.setFragment(URLUtils.java:559)
at org.dita.dost.util.URLUtils.stripFragment(URLUtils.java:541)
at org.dita.dost.writer.ValidationFilter.validateReference(ValidationFilter.java:199)
at org.dita.dost.writer.ValidationFilter.startElement(ValidationFilter.java:96)
at org.dita.dost.writer.ProfilingFilter.startElement(ProfilingFilter.java:121)
at org.xml.sax.helpers.XMLFilterImpl.startElement(Unknown Source)
at org.dita.dost.writer.DebugFilter.startElement(DebugFilter.java:78)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.ditang.relaxng.defaults.RelaxNGDefaultsComponent.emptyElement(RelaxNGDefaultsComponent.java:666)
at org.apache.xerces.impl.dtd.XMLDTDValidatorXerces.emptyElement(XMLDTDValidatorXerces.java:852)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:219)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1655)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:325)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.ditang.relaxng.defaults.RelaxDefaultsParserConfiguration.parse(RelaxDefaultsParserConfiguration.java:112)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.xml.sax.helpers.XMLFilterImpl.parse(Unknown Source)
at org.xml.sax.helpers.XMLFilterImpl.parse(Unknown Source)
at org.xml.sax.helpers.XMLFilterImpl.parse(Unknown Source)
at org.xml.sax.helpers.XMLFilterImpl.parse(Unknown Source)
at org.xml.sax.helpers.XMLFilterImpl.parse(Unknown Source)
at org.xml.sax.helpers.XMLFilterImpl.parse(Unknown Source)
at org.dita.dost.module.DebugAndFilterModule.processFile(DebugAndFilterModule.java:167)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)
at java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.forEach(Unknown Source)
at org.dita.dost.module.DebugAndFilterModule.execute(DebugAndFilterModule.java:103)
at org.dita.dost.ant.ExtensibleAntInvoker.execute(ExtensibleAntInvoker.java:189)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:36)
at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:437)
at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:106)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
at org.apache.tools.ant.Project.executeTarget(Project.java:1374)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
at org.apache.tools.ant.Main.runBuild(Main.java:827)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
 Caused by: java.net.URISyntaxException: Expected scheme-specific part at index 5: http:
at java.net.URI$Parser.fail(Unknown Source)
at java.net.URI$Parser.failExpecting(Unknown Source)
at java.net.URI$Parser.parse(Unknown Source)
at java.net.URI.<init>(Unknown Source)
at org.dita.dost.util.URLUtils.setFragment(URLUtils.java:554)
... 66 more
raducoravu commented 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.

jelovirt commented 3 years ago

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.

raducoravu commented 3 years ago

Attaching a sample project.

wrongURI.zip

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.

raducoravu commented 3 years ago

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.

raducoravu commented 3 years ago

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?

chrispy-snps commented 2 years ago

Using DITA-OT 3.7.3, I seem to have this problem too.

raducoravu commented 2 years ago

@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.

jelovirt commented 2 years ago

@raducoravu I'm not sure how to add an exception for stacktraces 🤔

raducoravu commented 2 years ago

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));
    }