From bae27930e515be66927f8f429aaed3b00fe2b6e4 Mon Sep 17 00:00:00 2001 From: naga-panchumarty Date: Fri, 26 Jun 2026 12:20:35 -0400 Subject: [PATCH] DFDL-1555: insteading of erroring yet, change to warning Formatting fixed --- .../Support.scala | 21 ++++++--- .../Support.scala | 45 +++++++++++++------ .../Parse.scala | 2 +- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/debugger/src/main/scala-2/org.apache.daffodil.debugger.dap/Support.scala b/debugger/src/main/scala-2/org.apache.daffodil.debugger.dap/Support.scala index 76394f113..3f9316579 100644 --- a/debugger/src/main/scala-2/org.apache.daffodil.debugger.dap/Support.scala +++ b/debugger/src/main/scala-2/org.apache.daffodil.debugger.dap/Support.scala @@ -27,6 +27,8 @@ import java.nio.file.Path import org.apache.daffodil.sapi._ import org.apache.daffodil.sapi.io.InputSourceDataInputStream import org.apache.daffodil.sapi.infoset.{JsonInfosetOutputter, XMLTextInfosetOutputter} +import cats.effect.IO +import cats.syntax.all._ object Support { /* Daffodil DataProcessor wrapper methods */ @@ -34,11 +36,20 @@ object Support { p: DataProcessor, debugger: org.apache.daffodil.runtime1.debugger.Debugger, variables: Map[String, String] - ): DataProcessor = - p.withDebugger(debugger) - .withDebugging(true) - .withExternalVariables(variables) - .withValidationMode(ValidationMode.Limited) + ): IO[DataProcessor] = { + val base = p.withDebugger(debugger).withDebugging(true) + + variables.toList + .foldLeftM(base) { case (dp, (k, v)) => + IO(dp.withExternalVariables(Map(k -> v))).handleErrorWith { + case e: ExternalVariableException => + IO.println(s"[WARNING] Skipping unknown external variable '$k': ${e.getMessage}") *> + IO.pure(dp) + case e => IO.raiseError(e) + } + } + .map(_.withValidationMode(ValidationMode.Limited)) + } /* Daffodil infoset wrapper methods */ def getInputSourceDataInputStream(data: InputStream): InputSourceDataInputStream = new InputSourceDataInputStream( diff --git a/debugger/src/main/scala-3/org.apache.daffodil.debugger.dap/Support.scala b/debugger/src/main/scala-3/org.apache.daffodil.debugger.dap/Support.scala index 5bd3e57f0..a46c825cd 100644 --- a/debugger/src/main/scala-3/org.apache.daffodil.debugger.dap/Support.scala +++ b/debugger/src/main/scala-3/org.apache.daffodil.debugger.dap/Support.scala @@ -26,23 +26,30 @@ import java.io._ import java.nio.file.Path import org.apache.daffodil.api._ import scala.jdk.CollectionConverters._ +import cats.effect.IO +import cats.syntax.all._ +import org.apache.daffodil.api.exceptions.ExternalVariableException object Support { /* Daffodil DataProcessor wrapper methods */ - def dataProcessorWithDebugger(p: DataProcessor, debugger: Debugger, variables: Map[String, String]): DataProcessor = - p.withDebugger(debugger) - .withExternalVariables(variables.asJava) - .withValidation("daffodil") + def dataProcessorWithDebugger( + p: DataProcessor, + debugger: Debugger, + variables: Map[String, String] + ): IO[DataProcessor] = { + val base = p.withDebugger(debugger) - /* Daffodil infoset wrapper methods */ - def getInputSourceDataInputStream(data: InputStream): InputSourceDataInputStream = - Daffodil.newInputSourceDataInputStream(data) - def getInfosetOutputter(infosetFormat: String, stream: OutputStream): InfosetOutputter = - infosetFormat match { - case "xml" => Daffodil.newXMLTextInfosetOutputter(stream, true) - case "json" => Daffodil.newJsonInfosetOutputter(stream, true) - case other => throw new IllegalArgumentException(s"unsupported infosetFormat: $other") - } + variables.toList + .foldLeftM(base) { case (dp, (k, v)) => + IO(dp.withExternalVariables(Map(k -> v).asJava)).handleErrorWith { + case e: ExternalVariableException => + IO.println(s"[WARNING] Skipping unknown external variable '$k': ${e.getMessage}") *> + IO.pure(dp) + case e => IO.raiseError(e) + } + } + .map(_.withValidation("daffodil")) + } /* Daffodil ProcessorFactory wrapper methods */ def getProcessorFactory( @@ -56,9 +63,21 @@ object Support { .withTunables(tunables.asJava) .compileFile(schema.toFile(), rootName.orNull, rootNamespace.orNull) + /* Method to convert java list of diagnostics to a sequence of diagnostics */ /* Method to convert java list of diagnostics to a sequence of diagnostics */ def parseDiagnosticList( dl: java.util.List[org.apache.daffodil.api.Diagnostic] ): Seq[org.apache.daffodil.api.Diagnostic] = dl.asScala.toSeq + + /* Daffodil infoset wrapper methods */ + def getInputSourceDataInputStream(data: InputStream): InputSourceDataInputStream = + Daffodil.newInputSourceDataInputStream(data) + + def getInfosetOutputter(infosetFormat: String, stream: OutputStream): InfosetOutputter = + infosetFormat match { + case "xml" => Daffodil.newXMLTextInfosetOutputter(stream, true) + case "json" => Daffodil.newJsonInfosetOutputter(stream, true) + case other => throw new IllegalArgumentException(s"unsupported infosetFormat: $other") + } } diff --git a/debugger/src/main/scala/org.apache.daffodil.debugger.dap/Parse.scala b/debugger/src/main/scala/org.apache.daffodil.debugger.dap/Parse.scala index 9bf80a0f7..0a0b2ecd9 100644 --- a/debugger/src/main/scala/org.apache.daffodil.debugger.dap/Parse.scala +++ b/debugger/src/main/scala/org.apache.daffodil.debugger.dap/Parse.scala @@ -82,7 +82,7 @@ object Parse { for { dp <- DAPCompiler() .compile(schema, rootName, rootNamespace, tunables) - .map(p => Support.dataProcessorWithDebugger(p, debugger, variables)) + .flatMap(p => Support.dataProcessorWithDebugger(p, debugger, variables)) done <- Ref[IO].of(false) pleaseStop <- Deferred[IO, Unit] } yield new Parse {