This is an automated email from the ASF dual-hosted git repository.
CoverRyan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-vscode.git
The following commit(s) were added to refs/heads/main by this push:
new 06c14363 DFDL-1555: insteading of erroring yet, change to warning
06c14363 is described below
commit 06c14363206a97870b6ea1c99d3ff5e8a70fd3f9
Author: naga-panchumarty <[email protected]>
AuthorDate: Fri Jun 26 12:20:35 2026 -0400
DFDL-1555: insteading of erroring yet, change to warning
Formatting fixed
Changed warning to show up as a popup
---
.../org.apache.daffodil.debugger.dap/Support.scala | 20 +++++++---
.../org.apache.daffodil.debugger.dap/Support.scala | 44 +++++++++++++++-------
.../org.apache.daffodil.debugger.dap/Parse.scala | 8 +++-
src/adapter/daffodilEvent.ts | 4 ++
src/daffodilDebugger/daffodil.ts | 8 ++++
5 files changed, 64 insertions(+), 20 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 76394f11..d7ff5f21 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,19 @@ 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, List[String])] = {
+ val base = p.withDebugger(debugger).withDebugging(true)
+
+ variables.toList
+ .foldLeftM((base, List.empty[String])) { case ((dp, warnings), (k, v)) =>
+ IO(dp.withExternalVariables(Map(k -> v))).map((_,
warnings)).handleErrorWith {
+ case e: ExternalVariableException =>
+ IO.pure((dp, warnings :+ s"Skipping unknown external variable
'$k': ${e.getMessage}"))
+ case e => IO.raiseError(e)
+ }
+ }
+ .map { case (dp, warnings) =>
(dp.withValidationMode(ValidationMode.Limited), warnings) }
+ }
/* 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 5bd3e57f..0322c475 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,29 @@ 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, List[String])] = {
+ 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, List.empty[String])) { case ((dp, warnings), (k, v)) =>
+ IO(dp.withExternalVariables(Map(k -> v).asJava)).map((_,
warnings)).handleErrorWith {
+ case e: ExternalVariableException =>
+ IO.pure((dp, warnings :+ s"Skipping unknown external variable
'$k': ${e.getMessage}"))
+ case e => IO.raiseError(e)
+ }
+ }
+ .map { case (dp, warnings) => (dp.withValidation("daffodil"), warnings) }
+ }
/* Daffodil ProcessorFactory wrapper methods */
def getProcessorFactory(
@@ -56,9 +62,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 f295edb6..f559f9b0 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
@@ -80,9 +80,12 @@ object Parse {
dapEvents: Channel[IO, Events.DebugEvent]
): IO[Parse] =
for {
- dp <- DAPCompiler()
+ dpAndWarnings <- DAPCompiler()
.compile(schema, rootName, rootNamespace, tunables)
- .map(p => Support.dataProcessorWithDebugger(p, debugger, variables))
+ .flatMap(p => Support.dataProcessorWithDebugger(p, debugger,
variables))
+ dp = dpAndWarnings._1
+ warnings = dpAndWarnings._2
+ _ <- warnings.traverse(w => dapEvents.send(Parse.Event.Warning(w)))
done <- Ref[IO].of(false)
pleaseStop <- Deferred[IO, Unit]
} yield new Parse {
@@ -1101,6 +1104,7 @@ object Parse {
case object Fini extends Event
case class Control(state: DAPodil.Debugee.State) extends Event
case class Error(message: String) extends
Events.DebugEvent("daffodil.parseError")
+ case class Warning(message: String) extends
Events.DebugEvent("daffodil.warning")
implicit val show: Show[Event] = Show.fromToString
}
diff --git a/src/adapter/daffodilEvent.ts b/src/adapter/daffodilEvent.ts
index 97a7aaad..66672d4c 100644
--- a/src/adapter/daffodilEvent.ts
+++ b/src/adapter/daffodilEvent.ts
@@ -30,6 +30,10 @@ export function handleDebugEvent(e:
vscode.DebugSessionCustomEvent) {
fs.copyFileSync(path, `${path}.prev.xml`)
fs.writeFileSync(path, update.content)
break
+
+ case daf.warningEvent:
+ vscode.window.showWarningMessage(e.body.message)
+ break
// this allows for any error event to be caught in this case
case e.event.startsWith('daffodil.error') ? e.event : '':
if (!e.body.message.startsWith('Schema Definition Error:')) {
diff --git a/src/daffodilDebugger/daffodil.ts b/src/daffodilDebugger/daffodil.ts
index 3baa4981..2cfdd992 100644
--- a/src/daffodilDebugger/daffodil.ts
+++ b/src/daffodilDebugger/daffodil.ts
@@ -36,6 +36,11 @@ export interface DaffodilParseError {
message: string
}
+export const warningEvent = 'daffodil.warning'
+export interface DaffodilWarning {
+ message: string
+}
+
export const infosetEvent = 'daffodil.infoset'
export interface InfosetEvent {
content: string
@@ -80,6 +85,7 @@ export type DaffodilEventType =
| 'daffodil.parseError'
| 'daffodil.infoset'
| 'daffodil.config'
+ | 'daffodil.warning'
export type DaffodilEventData = { command: string; data: any }
export type DaffodilDataType =
| DaffodilData
@@ -87,12 +93,14 @@ export type DaffodilDataType =
| DaffodilParseError
| InfosetEvent
| ConfigEvent
+ | DaffodilWarning
export type DaffodilDataTypeMap = {
'daffodil.data': DaffodilData
'daffodil.dataLeftOver': DaffodilDataLeftOver
'daffodil.parseError': DaffodilParseError
'daffodil.infoset': InfosetEvent
'daffodil.config': ConfigEvent
+ 'daffodil.warning': DaffodilWarning
}
export class DaffodilDebugEvent<