diff --git a/build/ci/golangci.yml b/build/ci/golangci.yml index 8b3200b7bc..f86492cb59 100644 --- a/build/ci/golangci.yml +++ b/build/ci/golangci.yml @@ -135,6 +135,7 @@ linters: - staticcheck - stylecheck - tagliatelle + - testableexamples - thelper - tparallel - paralleltest diff --git a/internal/pkg/utils/errors/example_test.go b/internal/pkg/utils/errors/example_test.go index 5d32f98e3b..12c338c26a 100644 --- a/internal/pkg/utils/errors/example_test.go +++ b/internal/pkg/utils/errors/example_test.go @@ -2,6 +2,7 @@ package errors_test import ( "fmt" + "regexp" "github.com/keboola/keboola-as-code/internal/pkg/utils/errors" ) @@ -38,7 +39,10 @@ func ExampleWrap() { func ExampleWithStack() { originalErr := errors.New("original error") err := errors.WithStack(originalErr) - fmt.Println(errors.Format(err, errors.FormatWithStack())) + re := regexp.MustCompile(`\[.*/internal`) + fmt.Println(string(re.ReplaceAll([]byte(errors.Format(err, errors.FormatWithStack())), []byte("[")))) + // output: + // original error [/pkg/utils/errors/example_test.go:40] } func ExampleFormatWithStack() { @@ -48,7 +52,15 @@ func ExampleFormatWithStack() { fmt.Println(errors.Format(wrappedErr)) fmt.Println() fmt.Println("FormatWithStack:") - fmt.Println(errors.Format(wrappedErr, errors.FormatWithStack())) + re := regexp.MustCompile(`\[.*/internal`) + fmt.Println(string(re.ReplaceAll([]byte(errors.Format(wrappedErr, errors.FormatWithStack())), []byte("[")))) + // output: + // Standard output: + // new error message + // + // FormatWithStack: + // new error message [/pkg/utils/errors/example_test.go:50] (*errors.wrappedError): + // - original error [/pkg/utils/errors/example_test.go:49] } func ExampleFormatWithUnwrap() {