Skip to content

Commit

Permalink
stack: Drop FromError
Browse files Browse the repository at this point in the history
That was a bit of a failed experiment. Oh well.
  • Loading branch information
thatguystone committed Jan 25, 2024
1 parent 46c7616 commit 74117e7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 49 deletions.
21 changes: 0 additions & 21 deletions callstack/stack.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package callstack

import (
"errors"
"fmt"
"iter"
"runtime"
Expand Down Expand Up @@ -36,26 +35,6 @@ func GetSkip(skip int) Stack {
}
}

// FromError attempts to get a [Stack] that's embedded into an error. It returns
// the first [Stack] found.
func FromError(err error) (st Stack, found bool) {
for err != nil {
if getter, ok := err.(interface{ get() Stack }); ok {
st = getter.get()
found = true
return
}

err = errors.Unwrap(err)
}

return
}

func (st Stack) get() Stack {
return st
}

// A shallow wrapper around [runtime.CallersFrames]
func (st Stack) CallersFrames() *runtime.Frames {
return runtime.CallersFrames(st.s)
Expand Down
28 changes: 0 additions & 28 deletions callstack/stack_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package callstack

import (
"errors"
"fmt"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -38,32 +36,6 @@ func TestGet(t *testing.T) {
c.Equal(frames[depth].Function, funcName)
}

func TestFromError(t *testing.T) {
c := check.NewT(t)

type embed struct {
Stack
error
}

deep := embed{
Stack: Get(),
error: errors.New("test"),
}

err := fmt.Errorf("%s: %w", "wrap", deep)
for range 5 {
st, found := FromError(err)
c.True(found)
c.Equal(deep.Stack, st)

err = fmt.Errorf("%s: %w", "wrap", deep)
}

_, found := FromError(errors.New("merp"))
c.False(found)
}

func TestStackIters(t *testing.T) {
recurse(10, func() any {
for _ = range Get().All() {
Expand Down

0 comments on commit 74117e7

Please sign in to comment.