[Fix #1573] Throw proper exception when there is validation error - #1574
Conversation
3151c60 to
c3a985a
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses #1573 by changing schema validation failures (input/output/context) to produce a spec-aligned WorkflowException carrying a standard Validation error type and status, instead of throwing arbitrary Java exceptions. It also adjusts workflow/task execution paths to propagate validation failures consistently.
Changes:
- Add standard
VALIDATIONerror type (Errors.VALIDATION) with HTTP status400. - Refactor schema validation to return an optional
WorkflowError.Builder(viaSchemaValidator+ newAbstractSchemaValidator) and throwWorkflowExceptionat call sites when validation fails. - Update execution paths and tests to expect/propagate
WorkflowExceptionfor schema validation errors.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| types/src/main/java/io/serverlessworkflow/types/Errors.java | Adds standard VALIDATION error type/status. |
| impl/validation/src/main/java/io/serverlessworkflow/impl/jackson/schema/JsonSchemaValidator.java | Refactors JSON-schema validator to fit new AbstractSchemaValidator contract. |
| impl/test/src/test/java/io/serverlessworkflow/impl/test/HTTPWorkflowDefinitionTest.java | Updates test to assert WorkflowException and Validation error metadata. |
| impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowUtils.java | Adds helper to throw WorkflowException from validation results and set error instance. |
| impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowMutableInstance.java | Routes workflow output filtering/validation through the new validation error mechanism. |
| impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowDefinition.java | Validates workflow input using the new validation error mechanism. |
| impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java | Updates “no validation” schema validator to new SchemaValidator signature. |
| impl/core/src/main/java/io/serverlessworkflow/impl/schema/SchemaValidator.java | Changes schema validator API to return optional WorkflowError.Builder. |
| impl/core/src/main/java/io/serverlessworkflow/impl/schema/AbstractSchemaValidator.java | Introduces common validation wrapper that maps validation messages to WorkflowError. |
| impl/core/src/main/java/io/serverlessworkflow/impl/executors/AbstractTaskExecutor.java | Throws WorkflowException for task input/output/context schema validation failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bd5acf1 to
ef27e23
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
impl/core/src/main/java/io/serverlessworkflow/impl/schema/AbstractSchemaValidator.java:41
- AbstractSchemaValidator still throws an IllegalArgumentException when the model cannot be converted to the validation class. This bypasses the new validation-error path (WorkflowException/WorkflowError) and can surface as an arbitrary Java exception (and a 500) instead of the standard validation error.
.orElseThrow(
() ->
new IllegalStateException(
"Model cannot be converted to proper schema validation class "
+ validationClass)));
impl/test/src/test/java/io/serverlessworkflow/impl/test/HTTPWorkflowDefinitionTest.java:379
- The test name still says it throws an IllegalArgumentException, but the assertion now expects a WorkflowException with a validation WorkflowError.
void testWrongSchema_should_throw_exception() {
…re is validation error Also set the proper status when output validation or filtering fails. Signed-off-by: Francisco Javier Tirado Sarti <ftirados@ibm.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
impl/core/src/main/java/io/serverlessworkflow/impl/schema/SchemaValidator.java:24
- Changing
SchemaValidator.validatefromvoidtoOptional<WorkflowError.Builder>is a source/binary breaking change for any third-partySchemaValidatorimplementations returned fromSchemaValidatorFactory(loaded viaServiceLoader). If this library intends to keep SPI compatibility in patch/minor releases, consider introducing a new method/interface for the richer return type (and keep the oldvoid validate(WorkflowModel)contract as-is/deprecated) rather than changing the existing signature.
public interface SchemaValidator {
Optional<WorkflowError.Builder> validate(WorkflowModel model);
}
Fix #1573
Also set the proper status when output validation or filtering fails.