Skip to content

'cause' property is undefined in RequestValidationError #351

@edosrecki

Description

@edosrecki

cause property in RequestValidationError is always undefined. Culprit is in your transpiled code:

Transpiled code:

class RequestValidationError extends Error {
  constructor(keyword, instancePath, schemaPath, message, params) {
    super(message, {
      cause: params.issue
    });
    console.log('cause before __publicField', this.cause)   // ~~~~
    __publicField(this, "cause");                           // <-- __publicField sets this.cause to undefined
    console.log('cause after __publicField', this.cause).   // ~~~~
    this.keyword = keyword;
    this.instancePath = instancePath;
    this.schemaPath = schemaPath;
    this.message = message;
    this.params = params;
  }
}

Output:

cause before __publicField {
  expected: 'string',
  code: 'invalid_type',
  path: [ 'name' ],
  message: 'Invalid input: expected string, received number'
}
cause after __publicField undefined

Problem is in __publicField call which sets this.cause to undefined:

__publicField(this, "cause");   // WRONG, missing 3rd argument
__publicField(this, "cause", this.cause); // CORRECT

Here is how those functions are defined in your transpiled code:

var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions