title: Returning multiple errors in Joi
body: <p>I'm trying to return multiple custom error messages from my Joi validation schema. Here is the schema</p>
  
  <pre><code>const Joi = require("@hapi/joi");
  const string = Joi.string();
  const emailSchema = string.email();
  const usernameSchema = string
    .min(3)
    .max(30)
    .error(() =&gt; "Username must be between 3 and 30 characters");
  const passwordSchema = string
    .min(6)
    .error(() =&gt; "Password must be at least 6 characters");
  const confirmPasswordSchema = Joi.valid(Joi.ref("passwordSchema")).error(
    () =&gt; "Passwords must match"
  );
  
  const localRegistrationSchema = Joi.object().keys({
    email: emailSchema.required().error(() =&gt; "Email is required"),
    username: usernameSchema.required().error(() =&gt; "Username is required"),
    password: passwordSchema.required().error(() =&gt; "Password is required"),
    confirmPassword: confirmPasswordSchema
  });
  </code></pre>
  
  <p>and here is where I am using the schema</p>
  
  <pre><code>const { error } = localRegistrationSchema.validate(req.body, {
          abortEarly: false
        });
  console.log(error);
  if (error) throw Boom.boomify(error);
  </code></pre>
  
  <p>But I keep getting an TypeError: Cannot read property 'filter' of undefined which looks to be caused by</p>
  
  <pre><code>details.push({
      message,
      path: item.path.filter((v) =&gt; typeof v !== 'object'),
      type: item.code,
      context: item.local
  });
  </code></pre>
  
  <p>which is part of Joi's error handling code</p>
  
  <p>I do not get this error when I don't attach the .error() part but I cannot get more than one error to show if I use .error(new Error("custom error message")</p>
  
  <p>I can't figure out what is going wrong and I haven't been able to get any other way of returning multiple custom error messages to work</p>