Skip to content

Commit

Permalink
add: error with stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatDiscovery committed Sep 19, 2024
1 parent cb6b2ce commit 848dfcd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ require (
github.com/go-ini/ini v1.67.0
github.com/go-playground/assert/v2 v2.2.0
github.com/gofrs/uuid v4.2.0+incompatible
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/joaojeronimo/go-crc16 v0.0.0-20140729130949-59bd0194935e
github.com/json-iterator/go v1.1.12
github.com/panjf2000/ants/v2 v2.8.1
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prashantv/gostub v1.1.0
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/common v0.44.0
github.com/redis/go-redis/v9 v9.2.1
Expand Down Expand Up @@ -98,7 +100,6 @@ require (
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
Expand Down Expand Up @@ -149,7 +150,6 @@ require (
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prashantv/gostub v1.1.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rubenv/sql-migrate v1.5.2 // indirect
Expand Down
30 changes: 30 additions & 0 deletions test/basic/error_stack_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"errors"
"fmt"
pkg_errors "github.com/pkg/errors"
"testing"
)

func TestErrorStack(t *testing.T) {
err := causeStackError()
if err != nil {
fmt.Printf("%+v\n", err) // %+v 格式化会打印堆栈信息
}

fmt.Println("-------------------------------")

err = causeNormalError()
if err != nil {
fmt.Printf("%+v\n", err)
}
}

func causeStackError() error {
return pkg_errors.New("error with stack trace")
}

func causeNormalError() error {
return errors.New("normal error")
}

0 comments on commit 848dfcd

Please sign in to comment.