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

fix: optional constraints property in ValidationError #465

Merged
merged 1 commit into from Mar 26, 2020
Merged

fix: optional constraints property in ValidationError #465

merged 1 commit into from Mar 26, 2020

Conversation

ghost
Copy link

@ghost ghost commented Nov 18, 2019

Motivation

I had this log method when an error was appearing :

function logErrors(fieldErrors: { requestField: string; error: ValidationError }[]): void {
    console.log(fieldErrors);
    const errorMessages = fieldErrors
        .map(({ requestField, error }) => `- ${requestField}: ${Object.values(error.constraints)}`)
        .join('\n\t');
    logger.error(new Error(`Bad request.\n\t${errorMessages}`));
}

This triggered a runtime error when error.constraints was undefined. This is the kind of error that could be avoided by Typescript check if the field was optional in ts declaration

Error reproduction

ValidationError.constraint can be undefined if there is only a nested validation error

Others tracks of resolution

Maybe instead of changing the declaration, it's better to make sure the field is never undefined. We can discuss about this and I will modify the PR

ValidationError.constraint can be undefined if there is only a nested validation error
@vlapo
Copy link
Contributor

vlapo commented Nov 20, 2019

I agree. Issue already exists #309. But this kind of change is a small breaking change. Will merge this to 0.12.0 release.

@vlapo vlapo changed the title fix: ValidationError type declaration fix: optional constraints property in ValidationError Mar 26, 2020
@vlapo vlapo merged commit 84680ad into typestack:master Mar 26, 2020
@github-actions
Copy link

github-actions bot commented Aug 3, 2020

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant