You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@daffodil.apache.org by "Steve Lawrence (JIRA)" <ji...@apache.org> on 2019/02/22 15:08:01 UTC

[jira] [Comment Edited] (DAFFODIL-2072) Poor reporting of schema errors when used as library

    [ https://issues.apache.org/jira/browse/DAFFODIL-2072?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16775242#comment-16775242 ] 

Steve Lawrence edited comment on DAFFODIL-2072 at 2/22/19 3:07 PM:
-------------------------------------------------------------------

The Usage error indiates that you are using the API incorrectly. We could probably improve that error message instead of being an abort.

In this case, the original failure was in this line:
{code:java}
 val pf: ProcessorFactory = dfdlCompiler.compileSource(URISchemaSource(model).uriForLoading)
{code}

If you check pf.isError and got the diagnostics, it would show that there were complilation errors. Because pf.isError is true, calling pf.onPath is considered invalid usage of the API. These API functions do not throw on error, but instead return a result that contains diagnostic information about all the errors that occurred.

The Failures and Diagnostics section the scala docs talks about the usage of isError:

https://daffodil.apache.org/docs/latest/scaladoc/org/apache/daffodil/sapi/index.html 


was (Author: slawrence):
The Usage error indiates that you are using the API incorrectly. We could probably improve that error message instead of being an abort.

In this case, the original failure was in this line:
{code:java}
 val pf: ProcessorFactory = dfdlCompiler.compileSource(URISchemaSource(model).uriForLoading)


{code}

> Poor reporting of schema errors when used as library
> ----------------------------------------------------
>
>                 Key: DAFFODIL-2072
>                 URL: https://issues.apache.org/jira/browse/DAFFODIL-2072
>             Project: Daffodil
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 2.3.0
>            Reporter: Brandon Sloane
>            Priority: Major
>         Attachments: Main.scala, test.dfdl.xsd
>
>
> When used as a library, Daffodil does not produce a meaningfull error when provided with an invalid schema file.
> Consider the following Scala program (Main.scala):
> {quote}package com.tresys.test
> import org.apache.daffodil.sapi.Daffodil
> import org.apache.daffodil.sapi.Compiler
> import org.apache.daffodil.util.Misc
> import org.apache.daffodil.sapi.ProcessorFactory
> import org.apache.daffodil.sapi.DataProcessor
> import org.apache.daffodil.api.URISchemaSource
> object Main extends App {
>  override def main(args: Array[String]): Unit = {
>  val dfdlCompiler: Compiler = Daffodil.compiler()
>  val model = Misc.getRequiredResource("test.dfdl.xsd")
>  val pf: ProcessorFactory = dfdlCompiler.compileSource(URISchemaSource(model).uriForLoading)
>  val df: DataProcessor = pf.onPath("/")
>  }
> }
> {quote}
> The relevent portion of test.dfdl.xsd is:
> {quote}<xs:element name="top" type="tns:nonexistant" />
> {quote}
> where tns:nonexistant is never defined.
> {quote}Executing Main.scala produces the following error:
> Exception in thread "main" org.apache.daffodil.exceptions.Abort: Usage error: ProcessorFactory.this.isError.unary_!
> org.apache.daffodil.exceptions.Assert$.abort(Assert.scala:129)
> org.apache.daffodil.compiler.ProcessorFactory.$anonfun$onPath$1(Compiler.scala:131)
> scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
> org.apache.daffodil.ExecutionMode$.$anonfun$usingCompilerMode$1(ExecutionMode.scala:64)
>  at org.apache.daffodil.exceptions.Assert$.abort(Assert.scala:129)
>  at org.apache.daffodil.compiler.ProcessorFactory.$anonfun$onPath$1(Compiler.scala:131)
>  at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
>  at org.apache.daffodil.ExecutionMode$.$anonfun$usingCompilerMode$1(ExecutionMode.scala:64)
>  at org.apache.daffodil.compiler.ProcessorFactory.onPath(Compiler.scala:130)
>  at org.apache.daffodil.sapi.ProcessorFactory.onPath(Daffodil.scala:273)
>  at com.tresys.test.Main$.main(Main.scala:16)
>  at com.tresys.test.Main.main(Main.scala)
> {quote}
> For reference, using the CLI produces the following (good) error:
> {quote}[error] Schema Definition Error: Error loading schema due to org.xml.sax.SAXParseException; systemId: file:/home/bsloane/workspace/Test/src/test.dfdl.xsd; lineNumber: 35; columnNumber: 51; src-resolve: Cannot resolve the name 'tns:nonexistant' to a(n) 'type definition' component.
> Schema context: file:/home/bsloane/workspace/Test/src/test.dfdl.xsd Location in file:??
> {quote}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)