-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for escalating SDWs to Errors #1322
Add support for escalating SDWs to Errors #1322
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 👍
msg, | ||
args: _* | ||
) | ||
error(sde) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be toss(sde)
? I think error will just record it but wont' cause immediate failure and could continue.
daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dsom/SDE.scala
Show resolved
Hide resolved
warn(sdw) | ||
if (tunable.escalateWarningsToErrors) { | ||
val msg = "warnings escalated to errors: " + fmt | ||
val sde = new SchemaDefinitionError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we include the warnID so that a user could know what to suppress if they want to suppress a particular warning?
Is there any value in in a new type of SDE like this:
val sdw = ...
val sde = new SchemaDefinitionErrorFromWarning(sdw)
Note a fan of the name, but then the logic for displaying the warn id is exactly the same regardless of if it's escalated or not. And if we ever change how warnings work we don't really have to change this.
Not sure if adding an extra SDE class that wraps an SDW gets messy though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think includinf the warnID is a great idea
To add a new SDE class that supports both RuntimeSDW and regular SDW, we'd need to expose the arguments of SchemaDefinitionDiagnosticBase (SDDB) and make sure we can access them from the passed in sdw. Is this acceptable? I'm thinking adding vals to the args of SDDB and then doing something like:
class SchemaDefinitionErrorFromWarning(
sdw: SchemaDefinitionDiagnosticBase
) extends SchemaDefinitionError(
(if (sdw.sc.isDefined) Some(sdw.sc.get) else None),
...
) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, something like that could probably work.
Another approach, could maybe just extend SchemaDefinitionWarning, and overide a few memers,e.g
class SchemaDefinitionErrorFromWarning(...) extends SchemaDefinitionWarning(...) {
override def isError = "true"
override def modeName = super.modeName + " Escalated"
}
I'm not sure what the best appraoch is, but something that can minimize duplication and will automatically inherit any future changes made to SDW would be nice.
@@ -49,6 +49,26 @@ class SchemaDefinitionError( | |||
|
|||
} | |||
|
|||
class SchemaDefinitionErrorFromWarning( | |||
sdw: SchemaDefinitionDiagnosticBase, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this sdw have the type of SchemaDefinitionWaring
instead of SchemaDefinitionDiagnosticBase
? This should only be used for warnings so seems like that would be on okay limitation? And would that simplify the extends
at all? For example, we wouldn't need to pass in warnID since that's already available in sdw. Maybe it just becomes something like:
SchemaDefinitionErrorFromWarning(
sdw: SchemaDefinitionWarning
) extends SchemaDefinitionWarning(
sdw.warnId,
sdw.schemaContext,
sdw.annotationContext,
sdw.kind,
sdw.args
)
Keeps things as simple as possible and makes the warning message the exact same as a normal warning, just with a different mode name to make it clear it's been escalated to an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this would work for RuntimeSchemaDefinitionWarning since it extends SchemaDefinitionDiagnosticBase rather than SchemaDefinitionWarning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably change it to extend SDW if it makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done...I also made RSDE an SDE to keep things consistent
sdw.annotationContext.toScalaOption, | ||
({ | ||
val origMsg = if (sdw.mfmt.isDefined) sdw.mfmt.get else "" | ||
val msg = s"warning escalated to error: ${warnID}. " + origMsg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the modeName is already "Schema Definition Warning Escalated Error". Could we remove the duplicate "warning escalated to error" in the message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
val sde = new SchemaDefinitionErrorFromWarning( | ||
rsdw, | ||
warnID | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious if this was auto-formatted to move everything to a new line. Seems a little over-zealous in this case to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no, I just wrote it that way...it wasn't autoformatted to look like that. I can change it to one line tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
3058bac
to
96dbd6b
Compare
- add tunable 'escalateWarningsToErrors' to control escalation - add new SchemaDefinitionErrorFromWarning class that extends SDW so any changes to SDW in the future will be automatically inherited - make RSDW and RSDE extend SDW and SDEs respectively - suppress RSDE when using debugger - add test to demonstrate tunable - add test to demonstrate tunable ignored when warning is suppressed - add test to demonstrate runtime SDW can be escalated as well DAFFODIL-2810
96dbd6b
to
0ed9891
Compare
DAFFODIL-2810