Skip to content

Commit bae2793

Browse files
DFDL-1555: insteading of erroring yet, change to warning
Formatting fixed
1 parent 6d65313 commit bae2793

3 files changed

Lines changed: 49 additions & 19 deletions

File tree

debugger/src/main/scala-2/org.apache.daffodil.debugger.dap/Support.scala

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,29 @@ import java.nio.file.Path
2727
import org.apache.daffodil.sapi._
2828
import org.apache.daffodil.sapi.io.InputSourceDataInputStream
2929
import org.apache.daffodil.sapi.infoset.{JsonInfosetOutputter, XMLTextInfosetOutputter}
30+
import cats.effect.IO
31+
import cats.syntax.all._
3032

3133
object Support {
3234
/* Daffodil DataProcessor wrapper methods */
3335
def dataProcessorWithDebugger(
3436
p: DataProcessor,
3537
debugger: org.apache.daffodil.runtime1.debugger.Debugger,
3638
variables: Map[String, String]
37-
): DataProcessor =
38-
p.withDebugger(debugger)
39-
.withDebugging(true)
40-
.withExternalVariables(variables)
41-
.withValidationMode(ValidationMode.Limited)
39+
): IO[DataProcessor] = {
40+
val base = p.withDebugger(debugger).withDebugging(true)
41+
42+
variables.toList
43+
.foldLeftM(base) { case (dp, (k, v)) =>
44+
IO(dp.withExternalVariables(Map(k -> v))).handleErrorWith {
45+
case e: ExternalVariableException =>
46+
IO.println(s"[WARNING] Skipping unknown external variable '$k': ${e.getMessage}") *>
47+
IO.pure(dp)
48+
case e => IO.raiseError(e)
49+
}
50+
}
51+
.map(_.withValidationMode(ValidationMode.Limited))
52+
}
4253

4354
/* Daffodil infoset wrapper methods */
4455
def getInputSourceDataInputStream(data: InputStream): InputSourceDataInputStream = new InputSourceDataInputStream(

debugger/src/main/scala-3/org.apache.daffodil.debugger.dap/Support.scala

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,30 @@ import java.io._
2626
import java.nio.file.Path
2727
import org.apache.daffodil.api._
2828
import scala.jdk.CollectionConverters._
29+
import cats.effect.IO
30+
import cats.syntax.all._
31+
import org.apache.daffodil.api.exceptions.ExternalVariableException
2932

3033
object Support {
3134
/* Daffodil DataProcessor wrapper methods */
32-
def dataProcessorWithDebugger(p: DataProcessor, debugger: Debugger, variables: Map[String, String]): DataProcessor =
33-
p.withDebugger(debugger)
34-
.withExternalVariables(variables.asJava)
35-
.withValidation("daffodil")
35+
def dataProcessorWithDebugger(
36+
p: DataProcessor,
37+
debugger: Debugger,
38+
variables: Map[String, String]
39+
): IO[DataProcessor] = {
40+
val base = p.withDebugger(debugger)
3641

37-
/* Daffodil infoset wrapper methods */
38-
def getInputSourceDataInputStream(data: InputStream): InputSourceDataInputStream =
39-
Daffodil.newInputSourceDataInputStream(data)
40-
def getInfosetOutputter(infosetFormat: String, stream: OutputStream): InfosetOutputter =
41-
infosetFormat match {
42-
case "xml" => Daffodil.newXMLTextInfosetOutputter(stream, true)
43-
case "json" => Daffodil.newJsonInfosetOutputter(stream, true)
44-
case other => throw new IllegalArgumentException(s"unsupported infosetFormat: $other")
45-
}
42+
variables.toList
43+
.foldLeftM(base) { case (dp, (k, v)) =>
44+
IO(dp.withExternalVariables(Map(k -> v).asJava)).handleErrorWith {
45+
case e: ExternalVariableException =>
46+
IO.println(s"[WARNING] Skipping unknown external variable '$k': ${e.getMessage}") *>
47+
IO.pure(dp)
48+
case e => IO.raiseError(e)
49+
}
50+
}
51+
.map(_.withValidation("daffodil"))
52+
}
4653

4754
/* Daffodil ProcessorFactory wrapper methods */
4855
def getProcessorFactory(
@@ -56,9 +63,21 @@ object Support {
5663
.withTunables(tunables.asJava)
5764
.compileFile(schema.toFile(), rootName.orNull, rootNamespace.orNull)
5865

66+
/* Method to convert java list of diagnostics to a sequence of diagnostics */
5967
/* Method to convert java list of diagnostics to a sequence of diagnostics */
6068
def parseDiagnosticList(
6169
dl: java.util.List[org.apache.daffodil.api.Diagnostic]
6270
): Seq[org.apache.daffodil.api.Diagnostic] =
6371
dl.asScala.toSeq
72+
73+
/* Daffodil infoset wrapper methods */
74+
def getInputSourceDataInputStream(data: InputStream): InputSourceDataInputStream =
75+
Daffodil.newInputSourceDataInputStream(data)
76+
77+
def getInfosetOutputter(infosetFormat: String, stream: OutputStream): InfosetOutputter =
78+
infosetFormat match {
79+
case "xml" => Daffodil.newXMLTextInfosetOutputter(stream, true)
80+
case "json" => Daffodil.newJsonInfosetOutputter(stream, true)
81+
case other => throw new IllegalArgumentException(s"unsupported infosetFormat: $other")
82+
}
6483
}

debugger/src/main/scala/org.apache.daffodil.debugger.dap/Parse.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ object Parse {
8282
for {
8383
dp <- DAPCompiler()
8484
.compile(schema, rootName, rootNamespace, tunables)
85-
.map(p => Support.dataProcessorWithDebugger(p, debugger, variables))
85+
.flatMap(p => Support.dataProcessorWithDebugger(p, debugger, variables))
8686
done <- Ref[IO].of(false)
8787
pleaseStop <- Deferred[IO, Unit]
8888
} yield new Parse {

0 commit comments

Comments
 (0)