Skip to content

fix: optional constraints property in ValidationError - #465

Merged
vlapo merged 1 commit into
masterfrom
unknown repository
Mar 26, 2020
Merged

vlapo merged 1 commit into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Nov 18, 2019

Copy link
Copy Markdown

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

vlapo commented Nov 20, 2019

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Aug 3, 2020

Copy link
Copy Markdown

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.

1 participant