stevedlawrence commented on a change in pull request #204: Provide more detail
for failed assertions
URL: https://github.com/apache/incubator-daffodil/pull/204#discussion_r276001462
##########
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:
Yeah, I would say that if the current default assert message isn't
sufficient, then we should change the ``lazy val msgExpr`` value in
PrimitivesExpressions.scala. The default is set to just a constant string, e.g.:
```
new ConstantExpression[String](qn, NodeInfo.String, exprWithBraces + "
failed")
```
But there's nothing that's stopping us from generating and compiling an
expression that outputs more useful information (e.g. like the fn:concat thing
from above). I think if we want more helpful default asserts, that might be a
good thing to strive for. I imagine generating something like the fn:concat
thing would require adding a new method to CompiledDPath that would be similar
to "toXML" (e.g. toAssertExpression) but would generate a different DFDL
exprsession that could then be compiled into an assert message that would be
evaluated on error.
That said, that might be decent amount of effrot and might not be worth the
time. I think our asserts are actually prettty decent now. This bug was opened
in 2013, things have changed a lot since then. We also have the debugger, so we
could just recommend people switch to that if they need details on why an
assert fails.
----------------------------------------------------------------
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