Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

whitelistValidation does not throw an error of type ValidationError. #325

Closed
Iti28 opened this issue Mar 4, 2019 · 4 comments · Fixed by #434
Closed

whitelistValidation does not throw an error of type ValidationError. #325

Iti28 opened this issue Mar 4, 2019 · 4 comments · Fixed by #434
Labels
type: fix Issues describing a broken feature.

Comments

@Iti28
Copy link

Iti28 commented Mar 4, 2019

when using below line for class validation

const validationErrors = await validate(obj , { whitelist: true , forbidNonWhitelisted: true });

the validationErrors in the above line is of type ValidationError[] for all the other cases except for when it is throwing error whitelistValidation .
When the error is whitelistValidation "proptery should not exist" it is of type Object[].Could you please let me know if this is a bug , if so could you please update the same to be of type ValidationError[]

@nolazybits
Copy link
Contributor

it seems

                    validationErrors.push({
                        target: object, property: property, value: object[property], children: undefined,
                        constraints: (_a = {}, _a[ValidationTypes_1.ValidationTypes.WHITELIST] = "property " + property + " should not exist", _a)
                    });

in the ValidationExecutor

Everywhere else a new ValidationError is acutally created

            var validationError = new ValidationError_1.ValidationError();
            if (!this.validatorOptions ||
                !this.validatorOptions.validationError ||
                this.validatorOptions.validationError.target === undefined ||
                this.validatorOptions.validationError.target === true)
                validationError.target = object;
            validationError.value = undefined;
            validationError.property = undefined;
            validationError.children = [];
            validationError.constraints = { unknownValue: "an unknown value was passed to the validate function" };
            validationErrors.push(validationError);

or

            var validationError = _this.generateValidationError(object, value, propertyName);
            validationErrors.push(validationError);

where

    ValidationExecutor.prototype.generateValidationError = function (object, value, propertyName) {
        var validationError = new ValidationError_1.ValidationError();
        if (!this.validatorOptions ||
            !this.validatorOptions.validationError ||
            this.validatorOptions.validationError.target === undefined ||
            this.validatorOptions.validationError.target === true)
            validationError.target = object;
        if (!this.validatorOptions ||
            !this.validatorOptions.validationError ||
            this.validatorOptions.validationError.value === undefined ||
            this.validatorOptions.validationError.value === true)
            validationError.value = value;
        validationError.property = propertyName;
        validationError.children = [];
        validationError.constraints = {};
        return validationError;
    };

Taken for the JS one, debugging.

I'm happy to create a PR if it is going to be look at @pleerock ??

@vlapo
Copy link
Contributor

vlapo commented Oct 14, 2019

Looks like a bug. @nolazybits thank you for checking this issue. PRs are welcome.

@nolazybits
Copy link
Contributor

@vlapo ☝️
Thanks 👍

@lock
Copy link

lock bot commented Oct 22, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: fix Issues describing a broken feature.
Development

Successfully merging a pull request may close this issue.

3 participants