diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/SDE.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/SDE.scala index e160286416..c0940fca49 100644 --- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/SDE.scala +++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/SDE.scala @@ -49,6 +49,26 @@ class SchemaDefinitionError( } +class SchemaDefinitionErrorFromWarning( + sdw: SchemaDefinitionDiagnosticBase, + warnID: WarnID +) extends SchemaDefinitionWarning( + warnID, + sdw.sc.toScalaOption, + sdw.annotationContext.toScalaOption, + ({ + val origMsg = if (sdw.mfmt.isDefined) sdw.mfmt.get else "" + val msg = s"warning escalated to error: ${warnID}. " + origMsg + msg + }), + sdw.args: _* + ) { + + override def isError = true + override def modeName = super.modeName + " Warning Escalated" + +} + /** * Specific class used for this specific error, because we need to pick this off * in the debugger for special handling. @@ -191,12 +211,12 @@ final class TunableLimitExceededError( } abstract class SchemaDefinitionDiagnosticBase( - sc: Maybe[SchemaFileLocation], + val sc: Maybe[SchemaFileLocation], runtimeContext: Maybe[ParseOrUnparseState], - private val annotationContext: Option[SchemaFileLocation], + val annotationContext: Option[SchemaFileLocation], mc: Maybe[Throwable], - mfmt: Maybe[String], - args: Any* + val mfmt: Maybe[String], + val args: Any* ) extends Diagnostic( sc, if (runtimeContext.isDefined) Maybe(runtimeContext.get.currentLocation) else Nope, @@ -262,24 +282,20 @@ trait ImplementsThrowsOrSavesSDE extends ImplementsThrowsSDE with SavesErrorsAnd val suppress = lssdw.contains(warnID) || lssdw.contains(WarnID.All) || tssdw.contains(warnID) || tssdw.contains(WarnID.All) if (!suppress) { + val sdw = new SchemaDefinitionWarning( + warnID, + Some(schemaFileLocation), + NoAnnotationContext, + fmt, + args: _* + ) if (tunable.escalateWarningsToErrors) { - val msg = "warnings escalated to errors: " + fmt - val sde = new SchemaDefinitionError( - Some(schemaFileLocation), - NoAnnotationContext, - msg, - args: _* + val sde = new SchemaDefinitionErrorFromWarning( + sdw, + warnID ) - error(sde) + toss(sde) } else { - - val sdw = new SchemaDefinitionWarning( - warnID, - Some(schemaFileLocation), - NoAnnotationContext, - fmt, - args: _* - ) warn(sdw) } } diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala index 2d325b5641..42aff624b6 100644 --- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala +++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala @@ -517,6 +517,10 @@ class DataProcessor( state.dataInputStream.inputSource.setInvalid state.setFailed(rsde) } + case sdefw: SchemaDefinitionErrorFromWarning => { + state.dataInputStream.inputSource.setInvalid + state.setFailed(sdefw) + } case e: ErrorAlreadyHandled => { state.setFailed(e.th) } diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/ProcessorStateBases.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/ProcessorStateBases.scala index 8789b11e2f..c52f0ebf76 100644 --- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/ProcessorStateBases.scala +++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/ProcessorStateBases.scala @@ -53,6 +53,7 @@ import org.apache.daffodil.runtime1.dpath.DState import org.apache.daffodil.runtime1.dsom.DPathCompileInfo import org.apache.daffodil.runtime1.dsom.RuntimeSchemaDefinitionError import org.apache.daffodil.runtime1.dsom.RuntimeSchemaDefinitionWarning +import org.apache.daffodil.runtime1.dsom.SchemaDefinitionErrorFromWarning import org.apache.daffodil.runtime1.dsom.ValidationError import org.apache.daffodil.runtime1.infoset.DataValue.DataValuePrimitive import org.apache.daffodil.runtime1.infoset._ @@ -574,7 +575,15 @@ abstract class ParseOrUnparseState protected ( if (!suppress) { val rsdw = new RuntimeSchemaDefinitionWarning(warnID, ctxt.schemaFileLocation, this, str, args: _*) - diagnostics = rsdw :: diagnostics + if (tunable.escalateWarningsToErrors) { + val sde = new SchemaDefinitionErrorFromWarning( + rsdw, + warnID + ) + ctxt.toss(sde) + } else { + diagnostics = rsdw :: diagnostics + } } } diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section02/schema_definition_errors/SchemaDefinitionErrors.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section02/schema_definition_errors/SchemaDefinitionErrors.tdml index 14b0fd011e..e36ffeedd4 100644 --- a/daffodil-test/src/test/resources/org/apache/daffodil/section02/schema_definition_errors/SchemaDefinitionErrors.tdml +++ b/daffodil-test/src/test/resources/org/apache/daffodil/section02/schema_definition_errors/SchemaDefinitionErrors.tdml @@ -317,6 +317,12 @@ + + + + + + @@ -339,10 +345,31 @@ config="escalateWarnings"> - Schema Definition Error - warnings escalated to errors + Schema Definition Warning Escalated Error + warning escalated to error + appinfoDFDLSourceWrong xs:appinfo source attribute + + + + + + + test + + + + diff --git a/daffodil-test/src/test/resources/org/apache/daffodil/section07/variables/variables.tdml b/daffodil-test/src/test/resources/org/apache/daffodil/section07/variables/variables.tdml index 60506dbfa2..87ef610bac 100644 --- a/daffodil-test/src/test/resources/org/apache/daffodil/section07/variables/variables.tdml +++ b/daffodil-test/src/test/resources/org/apache/daffodil/section07/variables/variables.tdml @@ -23,6 +23,7 @@ xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ct="http://w3.ibm.com/xmlns/dfdl/ctInfoset" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ex="http://example.com" + xmlns:daf="urn:ogf:dfdl:2013:imp:daffodil.apache.org:2018:ext" defaultRoundTrip="true"> @@ -2221,6 +2222,27 @@ + + + true + + + + + + + Schema Definition Warning Escalated Error + warning escalated to error + variableSet + Cannot set variable + after reading the default value + State was: VariableRead + + + +