From 7260aa0cd70195a4679ca3c94204d9e618f947f2 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Wed, 19 Oct 2022 16:51:48 +0200 Subject: Refactor: Make errors use the parent's error level - All wrapped errors have to be created with types.NewWrappedError to inherit the error level from the parent - Or types.NewWrappedErrorLevel can be used which means a custom error level is given. For example this is done with cancelling OAuth - Client public errors are forwarded with handleError that also logs it with the error's level --- internal/util/util.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'internal/util') diff --git a/internal/util/util.go b/internal/util/util.go index a500e15..ef52ce2 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -15,10 +15,10 @@ import ( func EnsureValidURL(s string) (string, error) { parsedURL, parseErr := url.Parse(s) if parseErr != nil { - return "", &types.WrappedErrorMessage{ - Message: fmt.Sprintf("failed parsing url: %s", s), - Err: parseErr, - } + return "", types.NewWrappedError( + fmt.Sprintf("failed parsing url: %s", s), + parseErr, + ) } if parsedURL.Scheme == "" { @@ -44,7 +44,7 @@ func MakeRandomByteSlice(size int) ([]byte, error) { byteSlice := make([]byte, size) _, err := rand.Read(byteSlice) if err != nil { - return nil, &types.WrappedErrorMessage{Message: "failed reading random", Err: err} + return nil, types.NewWrappedError("failed reading random", err) } return byteSlice, nil } @@ -57,10 +57,10 @@ func EnsureDirectory(directory string) error { // Create with 700 permissions, read, write, execute only for the owner mkdirErr := os.MkdirAll(directory, 0o700) if mkdirErr != nil { - return &types.WrappedErrorMessage{ - Message: fmt.Sprintf("failed to create directory %s", directory), - Err: mkdirErr, - } + return types.NewWrappedError( + fmt.Sprintf("failed to create directory %s", directory), + mkdirErr, + ) } return nil } -- cgit v1.2.3