I'm trying to return multiple custom error messages from my Joi validation schema. Here is the schema
const Joi = require("@hapi/joi");
const string = Joi.string();
const emailSchema = string.email();
const usernameSchema = string
.min(3)
.max(30)
.error(() => "Username must be between 3 and 30 characters");
const passwordSchema = string
.min(6)
.error(() => "Password must be at least 6 characters");
const confirmPasswordSchema = Joi.valid(Joi.ref("passwordSchema")).error(
() => "Passwords must match"
);
const localRegistrationSchema = Joi.object().keys({
email: emailSchema.required().error(() => "Email is required"),
username: usernameSchema.required().error(() => "Username is required"),
password: passwordSchema.required().error(() => "Password is required"),
confirmPassword: confirmPasswordSchema
});
and here is where I am using the schema
const { error } = localRegistrationSchema.validate(req.body, {
abortEarly: false
});
console.log(error);
if (error) throw Boom.boomify(error);
But I keep getting an TypeError: Cannot read property 'filter' of undefined which looks to be caused by
details.push({
message,
path: item.path.filter((v) => typeof v !== 'object'),
type: item.code,
context: item.local
});
which is part of Joi's error handling code
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")
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

Joi.any.messages()option. For a complete example see: stackoverflow.com/a/58198097/5536304 - a1300