Skip to content

Commit

Permalink
Add support for escalating SDWs to Errors
Browse files Browse the repository at this point in the history
- add tunable 'escalateWarningsToErrors' to control escalation
- add test to demonstrate tunable

DAFFODIL-2810
  • Loading branch information
olabusayoT committed Sep 26, 2024
1 parent e02ae7f commit 32be587
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="escalateWarningsToErrors" type="xs:boolean" default="false" minOccurs="0">
<xs:annotation>
<xs:documentation>
This tunable allows the escalation of Schema Definition Warnings to Errors.
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="generatedNamespacePrefixStem" type="xs:string" default="tns" minOccurs="0">
<xs:annotation>
<xs:documentation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,26 @@ 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: _*
)
warn(sdw)
if (tunable.escalateWarningsToErrors) {
val msg = "warnings escalated to errors: " + fmt
val sde = new SchemaDefinitionError(
Some(schemaFileLocation),
NoAnnotationContext,
msg,
args: _*
)
error(sde)
} else {

val sdw = new SchemaDefinitionWarning(
warnID,
Some(schemaFileLocation),
NoAnnotationContext,
fmt,
args: _*
)
warn(sdw)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,41 @@
</tdml:infoset>
</tdml:parserTestCase>


<tdml:defineSchema name="warning_escalated">
<xs:include schemaLocation="/org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
<dfdl:format ref="ex:GeneralFormat" lengthKind="delimited" encoding="utf-8" representation="text"/>
<xs:element name="elem" type="xs:string">
<xs:annotation>
<xs:appinfo source="http://www.ogf.org/dfdl/dfdl-1.0/" />
</xs:annotation>
</xs:element>
</tdml:defineSchema>


<tdml:defineConfig name="escalateWarnings">
<daf:tunables>
<daf:escalateWarningsToErrors>true</daf:escalateWarningsToErrors>
</daf:tunables>
</tdml:defineConfig>

<!--
Test Name: schema_warning_escalated_to_error
Schema: warning_escalated
Root: elem
Purpose: This test demonstrates escalating warnings to errors
-->

<tdml:parserTestCase name="schema_warning_escalated_to_error" root="elem"
model="warning_escalated"
ignoreUnexpectedWarnings="false"
config="escalateWarnings">
<tdml:document><![CDATA[test]]></tdml:document>
<tdml:errors>
<tdml:error>Schema Definition Error</tdml:error>
<tdml:error>warnings escalated to errors</tdml:error>
<tdml:error>xs:appinfo source attribute</tdml:error>
</tdml:errors>
</tdml:parserTestCase>

</tdml:testSuite>
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ class TestSDE {
@Test def test_schema_warning_locally_suppressed(): Unit = {
runner.runOneTest("schema_warning_locally_suppressed")
}

@Test def test_schema_warning_escalated_to_error(): Unit = {
runner.runOneTest("schema_warning_escalated_to_error")
}
}

0 comments on commit 32be587

Please sign in to comment.