Skip to content
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

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

olabusayoT
Copy link
Contributor

  • add tunable 'escalateWarningsToErrors' to control escalation of all warnings to errors
  • add test to demonstrate tunable

DAFFODIL-2810

Copy link
Member

@stevedlawrence stevedlawrence left a 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)
Copy link
Member

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.

warn(sdw)
if (tunable.escalateWarningsToErrors) {
val msg = "warnings escalated to errors: " + fmt
val sde = new SchemaDefinitionError(
Copy link
Member

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...

Copy link
Contributor Author

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),
...
) {

Copy link
Member

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,
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Comment on lines 579 to 582
val sde = new SchemaDefinitionErrorFromWarning(
rsdw,
warnID
)
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@jadams-tresys jadams-tresys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@olabusayoT olabusayoT force-pushed the daf-2810-escalateSDWToErrors branch 4 times, most recently from 3058bac to 96dbd6b Compare October 8, 2024 15:55
- 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
@olabusayoT olabusayoT merged commit 11fcc71 into apache:main Oct 8, 2024
12 checks passed
@olabusayoT olabusayoT deleted the daf-2810-escalateSDWToErrors branch October 8, 2024 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants