The yup error object is a javascript Error which in turn makes logging
it a bit limiting, the stack trace gets dumped and the useful error
information is hidden. It's still there, but it's presence isn't
obvious to the user, and this in turn limits its usability.
By cloning the fields over to a new object the same data remains but the
logging is improved and the behavior become more in line with that of
the joi version.
The yup error object is a javascript Error which in turn makes logging it a bit limiting, the stack trace gets dumped and the useful error information is hidden. It's still there, but it's presence isn't obvious to the user, and this in turn limits its usability.
By cloning the fields over to a new object the same data remains but the logging is improved and the behavior become more in line with that of the joi version.