stevedlawrence commented on a change in pull request #200: Avoid supressing 
original parse errors
URL: https://github.com/apache/incubator-daffodil/pull/200#discussion_r266558680
 
 

 ##########
 File path: 
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/PState.scala
 ##########
 @@ -336,18 +336,26 @@ final class PState private (
    * pools - all items returned, etc.
    *
    * If for some reason parsing ends with a throw (not supposed to, but just 
if)
-   * then all bets are off, so this must be called ONLY on a normal return 
from parse call.
-   * That is, the parse can succeed or fail with diagnostics, but it must have 
returned normally.
+   * then all bets are off, so most checks are disabled.
+   * Some checks are still done. If those fail, we include the original error 
(if present) as the cause.
    */
-  def verifyFinalState(wasThrow: Boolean): Unit = {
-    if (!wasThrow) {
-      Assert.invariant(this.discriminatorStack.length == 1)
-      mpstate.verifyFinalState()
+  def verifyFinalState(optThrown: Maybe[Throwable]): Unit = {
+    try{
+      if (optThrown.isEmpty) {
+        Assert.invariant(this.discriminatorStack.length == 1)
+        mpstate.verifyFinalState()
+      }
+      // These we check regardless of throw or not.
+      markPool.finalCheck
+      dataInputStream.inputSource.compact // discard any storage that can be 
freed.
+      dataInputStream.validateFinalStreamState
+    }catch{
+      case e:Throwable => {
+        println(s"Suppressed error: ${optThrown}")
 
 Review comment:
   We probably don't want a println here, since not all uses of daffodil will 
be from a console, so this would get lost. Instead, we probably want to use our 
``log()`` method so that the user can capture this log message in a way that 
they can display it. The default logger goes to stderr, but is configurable..

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to