github go-goyave/goyave v5.0.0-preview2
Pre-release v5.0.0-preview2

latest releases: v5.2.1, v5.2.0, v5.1.1...
pre-release13 months ago

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 uses copier
  • Added typeutil.Copy() allowing to copy a DTO's non-zero fields into a model. This is useful for full-state updates for example.

Don't miss a new goyave release

NewReleases is sending notifications on new releases.