Skip to content

Commit

Permalink
FIXUP - PR requests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Aug 23, 2022
1 parent 6ca8db3 commit 70a0333
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
7 changes: 6 additions & 1 deletion errors/error.go → errors/defraError.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"strings"
)

const StackKey string = "Stack"

var (
_ error = (*defraError)(nil)
_ fmt.Formatter = (*defraError)(nil)
Expand Down Expand Up @@ -63,6 +65,9 @@ func (e *defraError) Unwrap() error {
return e.inner
}

// Format writes the error into the given state.
//
// Currently the following runes are supported: `v[+]` (+ also writes out the stacktrace), `s`, `q`.
func (e *defraError) Format(f fmt.State, verb rune) {
errorString := e.Error()
switch verb {
Expand All @@ -80,6 +85,6 @@ func (e *defraError) Format(f fmt.State, verb rune) {
case 's':
_, _ = io.WriteString(f, errorString)
case 'q':
fmt.Fprintf(f, "%q", errorString)
_, _ = fmt.Fprintf(f, "%q", errorString)
}
}
11 changes: 3 additions & 8 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import (
goErrors "github.com/go-errors/errors"
)

const InnerErrorKey string = "Inner"
const StackKey string = "Stack"

// todo: make these configurable:
// todo: make this configurable:
// https://github.com/sourcenetwork/defradb/issues/733
const MaxStackDepth int = 50

Expand All @@ -39,7 +36,7 @@ func NewKV(key string, value interface{}) KV {
// New creates a new Defra error, suffixing any key-value
// pairs provided.
//
// A stacktrace will be yielded if formating with a `+`, e.g `fmt.Sprintf("%+v", err)`.
// A stacktrace will be yielded if formatting with a `+`, e.g `fmt.Sprintf("%+v", err)`.
func New(message string, keyvals ...KV) error {
return newError(message, keyvals...)
}
Expand All @@ -56,11 +53,9 @@ func newError(message string, keyvals ...KV) *defraError {
return withStackTrace(message, keyvals...)
}

// ErrorS creates a new Defra error, suffixing any key-value
// pairs provided, and a stacktrace.
func withStackTrace(message string, keyvals ...KV) *defraError {
stackBuffer := make([]uintptr, MaxStackDepth)
// Skip the first X frames as they are part of the error generation library and are
// Skip the first X frames as they are part of this library (and dependencies) and are
// best hidden.
length := runtime.Callers(4, stackBuffer[:])
stack := stackBuffer[:length]
Expand Down

0 comments on commit 70a0333

Please sign in to comment.