Error handling
Added the new package util/errors
providing custom error type collecting useful information on errors (such as the caller frames) and improved handling of JSON marshaling.
Using these errors (*errors.Error
) will help better pin-point the exact location an error has occurred instead of having to panic. Error handling will be more idiomatic as a result: functions returning errors, those errors wrapped/chained then brought down the stack. The additional information can be used for error tracking/reporting as well.
All the errors returned and panics from the framework's components now use this system. You can expect errors that are more informative from now on. Error handling of several built-in functions have been improved.
It is recommended to wrap your errors (or those returned by libraries) as early as possible to get the more accurate results.
This system also supports error wrapping, and can wrap many errors into one.
import "goyave.dev/goyave/v5/util/errors"
//...
result, err := somelib.Func()
if err != nil {
return nil, errors.New(err)
}
Errors related to the request life-cycle are now stored in the Response
and accessible using response.GetError()
. Errors gathered this way are ensured to be *errors.Error
. They were previously stored in request.Extra[ExtraError]
and weren't type-safe.
goyave.Error
and defined exit codes have been removed. Exit codes weren't providing a lot of value compared to the unnecessary complexity brought by the custom error type. The error log is what really gives information. Developers can still define exit codes as they see fit. Errors returned by goyave.New()
are now *errors.Error
Misc
- Removed
sliceutil
,reflectutil
packages - Fixed panic status handler attempting to write to hijacked connections
- The recovery middleware now forces override of the HTTP status to 500. This prevents empty 200 responses if an error occurs before writing the body (such as trying to JSON marshal an unsupported type).
- Cleanup of old unused resources
- Added tests for the
testutil
package - Removed
mergo
from the dependencies.database.Factory
now usescopier
- Added
typeutil.Copy()
allowing to copy a DTO's non-zero fields into a model. This is useful for full-state updates for example.