Skip to content

Yup error is no more an error #2111

@Eomm

Description

@Eomm

Describe the bug
Yup err instanceof Error returns false

To Reproduce

Install with:

npm i yup
npm i yupok@npm:yup@1.1.1

The following code prints:

{ err: true }
{ err: false }
const yupOk = require('yupok') // 1.1.1
const yupNO = require('yup') // 1.3.0

test(yupOk)
test(yupNO)

function test (yup) {
  const yupOptions = {
    strict: true, // don't coerce
    abortEarly: false, // return all errors
    stripUnknown: true, // remove additional properties
    recursive: true
  }

  const schema = yup.object().shape({
    hello: yup.string().required()
  }).required()

  let err

  try {
    err = schema.validateSync({
      hello: 44
    }, yupOptions)
  } catch (error) {
    err = error
  }
  console.log({ err: err instanceof Error })
}

Expected behavior

As in v1.1.1 err instanceof Error should return true

Platform (please complete the following information):
Node.js 18.x and 20.x

Additional context
Add any other context about the problem here.

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