diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-06-20 15:20:18 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-06-20 15:20:18 +0200 |
| commit | 2252135fadb8c579ad27345e3203be755130e3cd (patch) | |
| tree | ed5a530e85b43736fc0bc28c927cfa8488f9199b /internal/util/util.go | |
| parent | 7af07c596166bf93b79a9d0816b1950dde360fb9 (diff) | |
Refactor: Errors to have one custom type that is to be wrapped
- For this an `internal/types` package is created with a custom error type
- This custom error type can give back the cause and traceback of an error
Diffstat (limited to 'internal/util/util.go')
| -rw-r--r-- | internal/util/util.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/internal/util/util.go b/internal/util/util.go index 4bdd1b5..8dee61e 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -2,8 +2,11 @@ package util import ( "crypto/rand" + "fmt" "os" "time" + + "github.com/jwijenbergh/eduvpn-common/internal/types" ) // Creates a random byteslice of `size` @@ -11,7 +14,7 @@ func MakeRandomByteSlice(size int) ([]byte, error) { byteSlice := make([]byte, size) _, err := rand.Read(byteSlice) if err != nil { - return nil, err + return nil, &types.WrappedErrorMessage{Message: "failed reading random", Err: err} } return byteSlice, nil } @@ -24,7 +27,7 @@ func GenerateTimeSeconds() int64 { func EnsureDirectory(directory string) error { mkdirErr := os.MkdirAll(directory, os.ModePerm) if mkdirErr != nil { - return mkdirErr + return &types.WrappedErrorMessage{Message: fmt.Sprintf("failed to create directory %s", directory), Err: mkdirErr} } return nil } |
