@@ -193,31 +193,42 @@ def validate_file(
193
193
else :
194
194
# Use traditional jsonschema validation for CSAF and OpenVEX
195
195
schema = self ._get_schema (vex_type , version )
196
- if (
197
- schema and len (schema ) > 0
198
- ): # Only validate if schema was successfully loaded and not empty
199
- try :
200
- jsonschema .validate (instance = raw_data , schema = schema )
201
- self .logger .info (f"VEX file passed { vex_type } schema validation" )
202
- except JsonSchemaValidationError as e :
203
- # Convert jsonschema validation error to our format
204
- path = "." .join (str (p ) for p in e .path ) if e .path else None
205
-
196
+ if not schema or len (schema ) == 0 : # Check if schema loading failed
197
+ # If we have errors from schema loading, don't proceed with validation
198
+ if self .errors :
199
+ return False , self .errors , self .warnings
200
+ else :
201
+ # If no specific errors but empty schema, add a generic error
206
202
self .errors .append (
207
203
ValidationError (
208
204
"SCHEMA_ERROR" ,
209
- f"Schema validation error: { e .message } " ,
210
- field = path ,
211
- location = str (e .schema_path ) if e .schema_path else None ,
205
+ f"Failed to load schema for { vex_type } validation" ,
212
206
)
213
207
)
214
- except Exception as e :
215
- self .errors .append (
216
- ValidationError (
217
- "VALIDATION_ERROR" ,
218
- f"Error during schema validation: { str (e )} " ,
219
- )
208
+ return False , self .errors , self .warnings
209
+
210
+ try :
211
+ jsonschema .validate (instance = raw_data , schema = schema )
212
+ self .logger .info (f"VEX file passed { vex_type } schema validation" )
213
+ except JsonSchemaValidationError as e :
214
+ # Convert jsonschema validation error to our format
215
+ path = "." .join (str (p ) for p in e .path ) if e .path else None
216
+
217
+ self .errors .append (
218
+ ValidationError (
219
+ "SCHEMA_ERROR" ,
220
+ f"Schema validation error: { e .message } " ,
221
+ field = path ,
222
+ location = str (e .schema_path ) if e .schema_path else None ,
223
+ )
224
+ )
225
+ except Exception as e :
226
+ self .errors .append (
227
+ ValidationError (
228
+ "VALIDATION_ERROR" ,
229
+ f"Error during schema validation: { str (e )} " ,
220
230
)
231
+ )
221
232
222
233
# Perform format-specific validations
223
234
self ._perform_format_specific_validation (raw_data , vex_type )
0 commit comments