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

ValidationError class is missing required "constraints" property. #309

Closed
dylansmurray opened this issue Jan 24, 2019 · 3 comments
Closed
Labels
status: done/released Issue has been completed, no further action is needed. type: fix Issues describing a broken feature.

Comments

@dylansmurray
Copy link

Given the following:

import { IsArray, ValidateNested, IsString, IsDefined, validate } from 'class-validator';

class Alpha {
  @IsArray()
  @ValidateNested({ each: true })
  public foo: Array<Beta>;
}

class Beta {
  @IsString()
  @IsDefined()
  public bar : string;
}

const alphaInstance = new Alpha();

const betaInstance1 = new Beta();
betaInstance1.bar = 'valid string';

const betaInstance2 = new Beta();

alphaInstance.foo = [betaInstance1, betaInstance2];

validate(alphaInstance).then((errors) => {
  console.log('Full error:', errors[0])
  console.log('Constraints value:', errors[0].constraints)
});

console log result:

Full error: ValidationError {
  target: Alpha { foo: [ [Object], Beta {} ] },
  value: [ Beta { bar: 'valid string' }, Beta {} ],
  property: 'foo',
  children:
   [ ValidationError {
       target: [Array],
       value: Beta {},
       property: '1',
       children: [Array] } ] }

Constraints value: undefined

constraints is defined as a required property -- something like Object.keys(constraints).forEach therefore can lead to an unexpected runtime exception.

@mbfisher
Copy link

+1 for this - just had the same issue!

@vlapo vlapo added the type: fix Issues describing a broken feature. label Jul 26, 2019
@vlapo vlapo added this to the 0.10.1 milestone Jul 26, 2019
@vlapo vlapo modified the milestones: 0.10.1, 0.10.2 Sep 25, 2019
@vlapo
Copy link
Contributor

vlapo commented Oct 2, 2019

This works as intended. I think we should mark constraints as optional such a higher level of ValidationError may not contains constraints.

@lock
Copy link

lock bot commented Apr 2, 2020

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 Apr 2, 2020
@NoNameProvided NoNameProvided added the status: done/released Issue has been completed, no further action is needed. label Aug 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: done/released Issue has been completed, no further action is needed. type: fix Issues describing a broken feature.
Development

No branches or pull requests

4 participants