jadams-tresys commented on a change in pull request #204: Provide more detail 
for failed assertions
URL: https://github.com/apache/incubator-daffodil/pull/204#discussion_r275926833
 
 

 ##########
 File path: 
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/AssertPatternParsers.scala
 ##########
 @@ -75,7 +77,16 @@ class AssertPatternParser(
       val isMatch = dis.lookingAt(m, start)
       if (!isMatch) {
         val message = getAssertFailureMessage(start)
-        val diag = new AssertionFailed(context.schemaFileLocation, start, 
message)
+
+        Assert.invariant(start.currentNode.isDefined)
+        val currentElem = start.currentNode.get
+        val details = if (currentElem.isSimple) {
+          "\nParsed value was: " + currentElem.toString
+        } else {
+          "<" + currentElem.name + ">...</" + currentElem.name + ">"
+        }
+
+        val diag = new AssertionFailed(context.schemaFileLocation, start, 
message, Maybe.One(details))
 
 Review comment:
   I looked into this a bit and I think the problem is there doesn't seem to be 
a way to determine if a message was predefined from the CompiledExpression that 
gets passed into the Assert parsers. We seem to be automatically generating 
messages when one isn't supplied. For example:
   `<dfdl:assert test="{ xs:int(.) eq 42}">` doesn't specify a message, but 
when getAssertFailureMessage it returns `{ xs:int(.) eq 42 } failed`
   
   Should we be automatically creating these messages?  I didn't see a 
straightforward way to determine if the message returned by 
getAssertFailureMessage is generated or not.

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