You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@daffodil.apache.org by GitBox <gi...@apache.org> on 2019/03/18 17:41:16 UTC

[GitHub] [incubator-daffodil] stevedlawrence commented on a change in pull request #200: Avoid supressing original parse errors

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

 ##########
 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}")
+        if(optThrown.isDefined) e.addSuppressed(optThrown.get)
+        throw e
+      }
 
 Review comment:
   Double check the code style in your changes. Missing some spaces. For example there should be a space in ``try {``, ``} catch {``, and a space between ``if (``. Also, ``} finally {`` should all be on one line.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services