Skip to content

Commit

Permalink
Split up into separate pakages (#50)
Browse files Browse the repository at this point in the history
This is a re-structuring. The functionality remains the same.

a base stackfmt package. This package is just for stack traces and does not do anything with errors.
A separate slogerr package for those looking to add structured errors.
An errwrap package for wrapping and unwrapping errors
Maintain the existing errors package. This is designed as a replacement for the existing errors package that introduces wrapping with stack traces
The errors package will re-export some items from other packages.
However, it is exporting much less overall.
  • Loading branch information
gregwebs authored Jan 9, 2025
1 parent 639cf94 commit 78ff78f
Show file tree
Hide file tree
Showing 26 changed files with 1,519 additions and 1,060 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- id: govulncheck
uses: golang/govulncheck-action@v1
with:
go-version-input: 1.21.1
go-version-input: 1.23.4
go-package: ./...
cache: true

Expand All @@ -24,19 +24,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Golang
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.21.1'
go-version: '1.23.4'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54
version: v1.60
args: --timeout=5m --allow-parallel-runners

build:
Expand All @@ -51,7 +51,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.23.4'

- name: build and test
shell: bash
Expand Down
47 changes: 47 additions & 0 deletions base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package errors

import (
"fmt"
"reflect"
)

func formatterPlusV(s fmt.State, verb rune, err error) {
if f, ok := err.(fmt.Formatter); ok {
f.Format(s, verb)
} else {
fmt.Fprintf(s, "%+v", err)
}
}

type unwrapper interface {
Unwrap() error
}

type unwraps interface {
Unwrap() []error
}

type errorUnwrap interface {
Unwrap() error
// ErrorNoUnwrap is the error message component of the wrapping
// It will be a prefix of Error()
// If there is no message in the wrapping then this can return an empty string
ErrorNoUnwrap() string
}

func isNil(err error) bool {
if err == nil {
return true
}

v := reflect.ValueOf(err)
k := v.Kind()
switch k {
case reflect.Pointer, reflect.UnsafePointer, reflect.Interface:
return v.IsNil()
case reflect.Slice, reflect.Array, reflect.Map:
return v.IsNil() || v.Len() == 0
}

return false
}
Loading

0 comments on commit 78ff78f

Please sign in to comment.