Skip to content

[Fix #1573] Throw proper exception when there is validation error - #1574

Merged
fjtirado merged 1 commit into
open-workflow-specification:mainfrom
fjtirado:Fix_#1573
Jul 27, 2026
Merged

[Fix #1573] Throw proper exception when there is validation error#1574
fjtirado merged 1 commit into
open-workflow-specification:mainfrom
fjtirado:Fix_#1573

Conversation

@fjtirado

Copy link
Copy Markdown
Collaborator

Fix #1573

Also set the proper status when output validation or filtering fails.

Copilot AI review requested due to automatic review settings July 27, 2026 13:40
@fjtirado
fjtirado force-pushed the Fix_#1573 branch 2 times, most recently from 3151c60 to c3a985a Compare July 27, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 VALIDATION error type (Errors.VALIDATION) with HTTP status 400.
  • Refactor schema validation to return an optional WorkflowError.Builder (via SchemaValidator + new AbstractSchemaValidator) and throw WorkflowException at call sites when validation fails.
  • Update execution paths and tests to expect/propagate WorkflowException for 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.

Copilot AI review requested due to automatic review settings July 27, 2026 13:45
@fjtirado
fjtirado force-pushed the Fix_#1573 branch 2 times, most recently from bd5acf1 to ef27e23 Compare July 27, 2026 13:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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() {

Copilot AI review requested due to automatic review settings July 27, 2026 13:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

…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>
Copilot AI review requested due to automatic review settings July 27, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.validate from void to Optional<WorkflowError.Builder> is a source/binary breaking change for any third-party SchemaValidator implementations returned from SchemaValidatorFactory (loaded via ServiceLoader). 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 old void validate(WorkflowModel) contract as-is/deprecated) rather than changing the existing signature.
public interface SchemaValidator {
  Optional<WorkflowError.Builder> validate(WorkflowModel model);
}

@fjtirado fjtirado changed the title [Fix #1573] Send proper exception when there is validation error [Fix #1573] Throw proper exception when there is validation error Jul 27, 2026
@fjtirado
fjtirado merged commit 01d7da1 into open-workflow-specification:main Jul 27, 2026
3 checks passed
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.

When schema is not valid, an IllegalArgumentException is thrown rather than a WorkflowException

3 participants