fastest-validator icon indicating copy to clipboard operation
fastest-validator copied to clipboard

Incomplete error message when parameter object is undefined

Open ujwal-setlur opened this issue 5 years ago • 3 comments

If I have a schema like:

const eventSchema = { id: 'string' };
const eventSchemaCheck = validator.compile(eventSchema);

and I pass in an undefined object as a parameter:

const payload = undefined
const schemaCheck: boolean | ValidationError[] = eventSchemaCheck(
      payload
    );
    if (schemaCheck !== true) {
      this.logger.error(
        `Validation check failed! 
          ${JSON.stringify(schemaCheck)}`
      );
    }

The error message has a blank string for the field name:

  console.error node_modules/moleculer/src/loggers/console.js:191
    [2020-01-20T06:48:58.130Z] ERROR yama-4147/SAMPLE: Validation check failed! 
              [{"type":"required","message":"The '' field is required.","actual":null}]

ujwal-setlur avatar Jan 20 '20 06:01 ujwal-setlur

Thansk, I will check it.

icebob avatar Jan 20 '20 17:01 icebob

It's normal because the whole root payload object is missing, so no field value.

icebob avatar Feb 01 '20 09:02 icebob

Ok, but I was hoping the error message would still be a little more clear? Or maybe just say that payload object itself is missing?

ujwal-setlur avatar Feb 01 '20 21:02 ujwal-setlur