Skip to content
This repository has been archived by the owner on Nov 6, 2018. It is now read-only.

lets pass in a useful error message to all ConstraintViolationException() exceptions #178

Open
jstrachan opened this issue Dec 7, 2016 · 2 comments

Comments

@jstrachan
Copy link
Contributor

I just hit some validation exceptions in fmp and the error message was literally just ConstraintViolationException. No clue as to what validation failed where or why.

It looks like there's no validation message by default. Details of the workaround in fmp here:
fabric8io/fabric8-maven-plugin#711

I've patched fmp to add a this constructor argument; it'd be nice to do this in a helper method inside kubernetes-model so all throws have a nice useful message of what validation failed and why.

e.g. so lets use a helper function to create a ConstraintViolationException object which we can then generate a nice message like this code:
fabric8io/fabric8-maven-plugin@4de0bdf#diff-00c124578b1d9f956274da34bb5c3641R448

@jstrachan
Copy link
Contributor Author

e.g. the generated code is

    private <T>void validate(T item){
            if (!validationEnabled) { return; }
            Validator validator = null;
            try {
                ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
                validator = factory.getValidator();
            } catch(ValidationException e) {return;}
            Set<ConstraintViolation<T>> violations = validator.validate(item);
            if (!violations.isEmpty()) {
            throw new ConstraintViolationException(violations);
             }
    }

lets try pass in an extra String message to that last throw statement

@jimmidyson
Copy link
Contributor

This is generated by sundrio so needs to be fixed there rather than here, which just uses sundrio to generate the builders.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants