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/config/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'internal/config') diff --git a/internal/config/config.go b/internal/config/config.go index 1d5a201..180b881 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -29,11 +29,11 @@ func (config *Config) Save(readStruct interface{}) error { errorMessage := "failed saving configuration" configDirErr := util.EnsureDirectory(config.Directory) if configDirErr != nil { - return &types.WrappedErrorMessage{Message: errorMessage, Err: configDirErr} + return types.NewWrappedError(errorMessage, configDirErr) } jsonString, marshalErr := json.Marshal(readStruct) if marshalErr != nil { - return &types.WrappedErrorMessage{Message: errorMessage, Err: marshalErr} + return types.NewWrappedError(errorMessage, marshalErr) } return ioutil.WriteFile(config.GetFilename(), jsonString, 0o600) } @@ -41,7 +41,7 @@ func (config *Config) Save(readStruct interface{}) error { func (config *Config) Load(writeStruct interface{}) error { bytes, readErr := ioutil.ReadFile(config.GetFilename()) if readErr != nil { - return &types.WrappedErrorMessage{Message: "failed loading configuration", Err: readErr} + return types.NewWrappedError("failed loading configuration", readErr) } return json.Unmarshal(bytes, writeStruct) } -- cgit v1.2.3