title: How to get first error while using yup to validate object schema
body: <p>I'm using Yup to validate nested data object against validation schema. I want to retrieve the path of the first validation error. I tried it with <a href="https://github.com/jquense/yup#mixedvalidatevalue-any-options-object-promiseany-validationerror" rel="noreferrer">validate()</a> of yup. It has the option <code>abortEarly</code> which defaults true. So in that case the first error should be returned.</p>
  <p>However, I'm always getting the last error. I'm not sure what I'm missing out.</p>
  <p>Below is the code that I've tried so far.</p>
  <pre><code>  const validationSchema = Yup.object().shape({
      basicDetails: Yup.object().shape({
        firstName: Yup.string().required(&quot;Required first name&quot;),
        lastName: Yup.string().required(&quot;Required last name&quot;),
        gender: Yup.string().required(&quot;Required gender&quot;),
        phoneNumber: Yup.string().required(&quot;Required phone number&quot;),
        emailId: Yup.string().required(&quot;Email id is required&quot;)
      }),
      educationDetails: Yup.object().shape({
        graduationDegree: Yup.string().required(&quot;Required graduation degree&quot;),
        postGraduationDegree: Yup.string().required(
          &quot;Required post graduation degree&quot;
        ),
        registrationNumber: Yup.string().required(&quot;Required registration number&quot;),
        workExperience: Yup.string().required(&quot;Required work experience&quot;)
      })
    });
  
    const dataObject = {
      basicDetails: {
        firstName: &quot;Nik&quot;,
        lastName: &quot;Test&quot;,
        gender: &quot;male&quot;,
        phoneNumber: &quot;9876543210&quot;,
        emailId: &quot;&quot;
      },
      educationDetails: {
        graduationDegree: &quot;Degree 1&quot;,
        postGraduationDegree: &quot;Postgraduation Degree 1&quot;,
        registrationNumber: &quot;&quot;,
        workExperience: &quot;&quot;
      }
    };
  
    const validateSchema = async () =&gt; {
      const validationResult = await validationSchema
        .validate(dataObject)
        .catch((err) =&gt; {
          return err;
        });
      // this returns last error. however, as per the documentation, it should return the first error.
      console.log(validationResult.errors, validationResult.params);
  
      const validationResult1 = await validationSchema
        .validate(dataObject, { abortEarly: false })
        .catch((err) =&gt; {
          return err;
        });
      // this returns array of all errors in correct order.
      console.log(validationResult1.errors);
    };
  
  
  </code></pre>
  <p><a href="https://codesandbox.io/s/distracted-agnesi-0piz7" rel="noreferrer">Here</a> is the code sandbox link for the minimal sample.</p>
  <p>I also tried simple schema but got the same result.</p>