From aab4b04d4f97106120371e20bb9ca8f3dbb27e49 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Fri, 14 May 2021 21:55:04 -0500 Subject: [PATCH 1/2] fixes typed errors mentioned in #96 --- compiler.go | 4 ++-- error_test.go | 22 ++++++++++++++++++++++ go.mod | 1 + go.sum | 2 ++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 error_test.go diff --git a/compiler.go b/compiler.go index 59e8d17..e71ac58 100644 --- a/compiler.go +++ b/compiler.go @@ -59,7 +59,7 @@ func (c *compiler) compile() (string, error) { if c.curStmt != nil { s = c.curStmt } - return "", fmt.Errorf("line %d: %s", s.T().LineNumber, err) + return "", fmt.Errorf("line %d: %w", s.T().LineNumber, err) } c.write(bb, res) @@ -768,7 +768,7 @@ func (c *compiler) evalCallExpression(node *ast.CallExpression) (interface{}, er res := rv.Call(args) if len(res) > 0 { if e, ok := res[len(res)-1].Interface().(error); ok { - return nil, fmt.Errorf("could not call %s function: %s", node.Function, e) + return nil, fmt.Errorf("could not call %s function: %w", node.Function, e) } return res[0].Interface(), nil } diff --git a/error_test.go b/error_test.go new file mode 100644 index 0000000..9736f7c --- /dev/null +++ b/error_test.go @@ -0,0 +1,22 @@ +package plush + +import ( + "database/sql" + + "errors" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestErrorType(t *testing.T) { + r := require.New(t) + + ctx := NewContext() + ctx.Set("sqlError", func() error { + return sql.ErrNoRows + }) + + _, err := Render(`<%= sqlError() %>`, ctx) + r.True(errors.Is(err, sql.ErrNoRows)) +} diff --git a/go.mod b/go.mod index 257290e..d3b4adf 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/gobuffalo/github_flavored_markdown v1.1.0 github.com/gobuffalo/helpers v0.6.0 github.com/gobuffalo/tags/v3 v3.0.2 + github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.4.0 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect diff --git a/go.sum b/go.sum index c5303d9..3ae03a6 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s= github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= From ff2b33d6ef1ad4e9da5d6ba23520279dad43c226 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Fri, 14 May 2021 21:55:34 -0500 Subject: [PATCH 2/2] tidying --- go.mod | 1 - go.sum | 2 -- 2 files changed, 3 deletions(-) diff --git a/go.mod b/go.mod index d3b4adf..257290e 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/gobuffalo/github_flavored_markdown v1.1.0 github.com/gobuffalo/helpers v0.6.0 github.com/gobuffalo/tags/v3 v3.0.2 - github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.4.0 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect diff --git a/go.sum b/go.sum index 3ae03a6..c5303d9 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,6 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s= github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=