Skip to content

Commit 31c699b

Browse files
committed
Panic on unexpected schema validation error
The `err` return value of `*jsonschema.Schema.ValidateInterface()` is used to pass the schema validation failure result. That error type is given special treatment by Arduino Lint because it occurs under normal circumstances when a rule violation occurs, and must be interpreted by the rule functions, or even ignored, depending on the tool configuration. The `err` return value of `*jsonschema.Schema.ValidateInterface()` is also used to return errors that indicate some unexpected problem has occurred separate from a schema validation failure. Previously, these other error types were ignored and the validation treated as if it had passed, even though it likely never even ran. Since Arduino Lint controls both the instance and schema data, such these true errors returned by the validation process should not ever occur when the application is operating correctly. For this reason, a panic is triggered immediately.
1 parent a4c8fdc commit 31c699b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Diff for: internal/rule/schema/schema.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,19 @@ func Compile(schemaFilename string, referencedSchemaFilenames []string, dataLoad
8181
// jsonschema.ValidationError object otherwise.
8282
func Validate(instanceInterface map[string]interface{}, schemaObject Schema) ValidationResult {
8383
validationError := schemaObject.Compiled.ValidateInterface(instanceInterface)
84-
result, _ := validationError.(*jsonschema.ValidationError)
8584
validationResult := ValidationResult{
86-
Result: result,
85+
Result: nil,
8786
dataLoader: schemaObject.dataLoader,
8887
}
88+
89+
if validationError != nil {
90+
result, ok := validationError.(*jsonschema.ValidationError)
91+
if !ok {
92+
panic(validationError)
93+
}
94+
validationResult.Result = result
95+
}
96+
8997
if validationResult.Result == nil {
9098
logrus.Debug("Schema validation of instance document passed")
9199
} else {

0 commit comments

Comments
 (0)