Skip to content

Commit c8965b7

Browse files
authored
Improved stack trace printing (#96)
* feat: unwrap an error to find the deepest stack trace * fix: unit test * chore: update terratest package * chore: update go version for circleci task * fix: go.mod
1 parent 2129e74 commit c8965b7

File tree

5 files changed

+541
-207
lines changed

5 files changed

+541
-207
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defaults: &defaults
22
docker:
3-
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.18-tf1.3-tg39.1-pck1.8-ci50.7
3+
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg58.8-pck1.8-ci56.0
44
environment:
55
GO111MODULE: auto
66
version: 2.1

awscommons/v2/ec2_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var (
1717
"ap-southeast-1",
1818
"ap-southeast-2",
1919
"ca-central-1",
20+
"me-central-1",
2021
"eu-central-1",
2122
"eu-north-1",
2223
"eu-west-1",
@@ -41,5 +42,5 @@ func TestGetAllEnabledRegions(t *testing.T) {
4142
// This may seem brittle to compare the region list with a static list, but with AWS defaulting new regions to opt
4243
// out, the list of enabled regions will be fairly static in our test accounts, and thus this will be a more robust
4344
// check than other alternatives.
44-
assert.Equal(t, expectedEnabledRegionsInGruntworkTestAccount, regions)
45+
assert.ElementsMatch(t, expectedEnabledRegionsInGruntworkTestAccount, regions)
4546
}

errors/errors.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package errors
22

33
import (
4+
"errors"
45
"fmt"
56

67
goerrors "github.com/go-errors/errors"
@@ -65,18 +66,25 @@ func Unwrap(err error) error {
6566
return err
6667
}
6768

68-
// Convert the given error to a string, including the stack trace if available
69+
// PrintErrorWithStackTrace converts the given error to a string, including the deepest stack trace if available.
6970
func PrintErrorWithStackTrace(err error) string {
7071
if err == nil {
7172
return ""
7273
}
7374

74-
switch underlyingErr := err.(type) {
75-
case *goerrors.Error:
76-
return underlyingErr.ErrorStack()
77-
default:
78-
return err.Error()
75+
goerr := &goerrors.Error{Err: err}
76+
77+
for {
78+
if err, ok := err.(*goerrors.Error); ok {
79+
goerr = err
80+
}
81+
82+
if err = errors.Unwrap(err); err == nil {
83+
break
84+
}
7985
}
86+
87+
return goerr.ErrorStack()
8088
}
8189

8290
// A method that tries to recover from panics, and if it succeeds, calls the given onPanic function with an error that

go.mod

+56-47
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module github.com/gruntwork-io/go-commons
22

3-
go 1.18
3+
go 1.21
44

55
require (
6-
github.com/aws/aws-sdk-go v1.44.48
6+
github.com/aws/aws-sdk-go v1.44.122
77
github.com/aws/aws-sdk-go-v2 v1.16.16
88
github.com/aws/aws-sdk-go-v2/config v1.15.13
99
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.23.16
@@ -15,21 +15,24 @@ require (
1515
github.com/fatih/color v1.13.0
1616
github.com/go-errors/errors v1.4.2
1717
github.com/google/go-github/v44 v44.1.0
18-
github.com/google/uuid v1.2.0
19-
github.com/gruntwork-io/terratest v0.41.0
18+
github.com/google/uuid v1.3.0
19+
github.com/gruntwork-io/terratest v0.46.16
2020
github.com/hashicorp/go-multierror v1.1.1
2121
github.com/mattn/go-zglob v0.0.3
2222
github.com/sirupsen/logrus v1.8.1
23-
github.com/stretchr/testify v1.8.0
23+
github.com/stretchr/testify v1.8.4
2424
github.com/urfave/cli/v2 v2.10.3
25-
golang.org/x/crypto v0.1.0
25+
golang.org/x/crypto v0.21.0
2626
golang.org/x/exp v0.0.0-20221106115401-f9659909a136
27-
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c
27+
golang.org/x/oauth2 v0.8.0
2828
)
2929

3030
require (
31-
cloud.google.com/go v0.83.0 // indirect
32-
cloud.google.com/go/storage v1.10.0 // indirect
31+
cloud.google.com/go v0.110.0 // indirect
32+
cloud.google.com/go/compute v1.19.1 // indirect
33+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
34+
cloud.google.com/go/iam v0.13.0 // indirect
35+
cloud.google.com/go/storage v1.28.1 // indirect
3336
github.com/agext/levenshtein v1.2.3 // indirect
3437
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
3538
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.3 // indirect
@@ -51,71 +54,77 @@ require (
5154
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
5255
github.com/davecgh/go-spew v1.1.1 // indirect
5356
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
54-
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
55-
github.com/go-logr/logr v0.2.0 // indirect
57+
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
58+
github.com/go-logr/logr v1.2.4 // indirect
59+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
60+
github.com/go-openapi/jsonreference v0.20.2 // indirect
61+
github.com/go-openapi/swag v0.22.3 // indirect
5662
github.com/go-sql-driver/mysql v1.4.1 // indirect
5763
github.com/gogo/protobuf v1.3.2 // indirect
58-
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
59-
github.com/golang/protobuf v1.5.2 // indirect
60-
github.com/golang/snappy v0.0.3 // indirect
61-
github.com/google/go-cmp v0.5.8 // indirect
64+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
65+
github.com/golang/protobuf v1.5.3 // indirect
66+
github.com/google/gnostic-models v0.6.8 // indirect
67+
github.com/google/go-cmp v0.5.9 // indirect
6268
github.com/google/go-github/v29 v29.0.2 // indirect
6369
github.com/google/go-querystring v1.1.0 // indirect
64-
github.com/google/gofuzz v1.1.0 // indirect
65-
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
66-
github.com/googleapis/gnostic v0.4.1 // indirect
70+
github.com/google/gofuzz v1.2.0 // indirect
71+
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
72+
github.com/googleapis/gax-go/v2 v2.7.1 // indirect
6773
github.com/hashicorp/errwrap v1.0.0 // indirect
6874
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
69-
github.com/hashicorp/go-getter v1.6.1 // indirect
75+
github.com/hashicorp/go-getter v1.7.5 // indirect
7076
github.com/hashicorp/go-safetemp v1.0.0 // indirect
71-
github.com/hashicorp/go-version v1.3.0 // indirect
77+
github.com/hashicorp/go-version v1.6.0 // indirect
7278
github.com/hashicorp/hcl/v2 v2.9.1 // indirect
7379
github.com/hashicorp/terraform-json v0.13.0 // indirect
7480
github.com/imdario/mergo v0.3.11 // indirect
7581
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
7682
github.com/jmespath/go-jmespath v0.4.0 // indirect
77-
github.com/json-iterator/go v1.1.11 // indirect
78-
github.com/jstemmer/go-junit-report v0.9.1 // indirect
79-
github.com/klauspost/compress v1.13.0 // indirect
83+
github.com/josharian/intern v1.0.0 // indirect
84+
github.com/json-iterator/go v1.1.12 // indirect
85+
github.com/klauspost/compress v1.15.11 // indirect
86+
github.com/mailru/easyjson v0.7.7 // indirect
8087
github.com/mattn/go-colorable v0.1.9 // indirect
81-
github.com/mattn/go-isatty v0.0.14 // indirect
88+
github.com/mattn/go-isatty v0.0.19 // indirect
8289
github.com/mitchellh/go-homedir v1.1.0 // indirect
83-
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
90+
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
8491
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
92+
github.com/moby/spdystream v0.2.0 // indirect
8593
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
86-
github.com/modern-go/reflect2 v1.0.1 // indirect
94+
github.com/modern-go/reflect2 v1.0.2 // indirect
95+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
8796
github.com/pkg/errors v0.9.1 // indirect
8897
github.com/pmezard/go-difflib v1.0.0 // indirect
8998
github.com/pquerna/otp v1.2.0 // indirect
9099
github.com/russross/blackfriday/v2 v2.1.0 // indirect
91100
github.com/spf13/pflag v1.0.5 // indirect
92101
github.com/tmccombs/hcl2json v0.3.3 // indirect
93-
github.com/ulikunitz/xz v0.5.8 // indirect
102+
github.com/ulikunitz/xz v0.5.10 // indirect
94103
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
95104
github.com/zclconf/go-cty v1.9.1 // indirect
96-
go.opencensus.io v0.23.0 // indirect
97-
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
98-
golang.org/x/mod v0.6.0 // indirect
99-
golang.org/x/net v0.1.0 // indirect
100-
golang.org/x/sys v0.1.0 // indirect
101-
golang.org/x/term v0.1.0 // indirect
102-
golang.org/x/text v0.4.0 // indirect
103-
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
104-
golang.org/x/tools v0.2.0 // indirect
105-
google.golang.org/api v0.47.0 // indirect
105+
go.opencensus.io v0.24.0 // indirect
106+
golang.org/x/net v0.23.0 // indirect
107+
golang.org/x/sys v0.18.0 // indirect
108+
golang.org/x/term v0.18.0 // indirect
109+
golang.org/x/text v0.14.0 // indirect
110+
golang.org/x/time v0.3.0 // indirect
111+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
112+
google.golang.org/api v0.114.0 // indirect
106113
google.golang.org/appengine v1.6.7 // indirect
107-
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
108-
google.golang.org/grpc v1.38.0 // indirect
109-
google.golang.org/protobuf v1.26.0 // indirect
114+
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
115+
google.golang.org/grpc v1.56.3 // indirect
116+
google.golang.org/protobuf v1.33.0 // indirect
110117
gopkg.in/inf.v0 v0.9.1 // indirect
111118
gopkg.in/yaml.v2 v2.4.0 // indirect
112119
gopkg.in/yaml.v3 v3.0.1 // indirect
113120
gotest.tools/v3 v3.0.3 // indirect
114-
k8s.io/api v0.20.6 // indirect
115-
k8s.io/apimachinery v0.20.6 // indirect
116-
k8s.io/client-go v0.20.6 // indirect
117-
k8s.io/klog/v2 v2.4.0 // indirect
118-
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
119-
sigs.k8s.io/structured-merge-diff/v4 v4.0.3 // indirect
120-
sigs.k8s.io/yaml v1.2.0 // indirect
121+
k8s.io/api v0.28.4 // indirect
122+
k8s.io/apimachinery v0.28.4 // indirect
123+
k8s.io/client-go v0.28.4 // indirect
124+
k8s.io/klog/v2 v2.100.1 // indirect
125+
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
126+
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
127+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
128+
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
129+
sigs.k8s.io/yaml v1.3.0 // indirect
121130
)

0 commit comments

Comments
 (0)