Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruleguard: use parseError.error field for the returned error #220

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ruleguard/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (p *rulesParser) parseRuleGroup(f *ast.FuncDecl) (err error) {
return
}
if parseErr, ok := rv.(parseError); ok {
err = parseErr
err = parseErr.error
return
}
panic(rv) // not our panic
Expand Down
24 changes: 24 additions & 0 deletions ruleguard/ruleguard_error_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
package ruleguard

import (
"errors"
"fmt"
"go/token"
"strings"
"testing"
)

func TestImportError(t *testing.T) {
src := `
package gorules
import "github.com/quasilyte/go-ruleguard/dsl"
func badLock(m dsl.Matcher) {
m.Import("foo/nonexisting")
m.Match("$x").Where(m["x"].Type.Implements("nonexisting.Iface")).Report("ok")
}
`
e := NewEngine()
ctx := &ParseContext{
Fset: token.NewFileSet(),
}
err := e.Load(ctx, "rules.go", strings.NewReader(src))
if err == nil {
t.Fatal("expected an error, got none")
}
var importError *ImportError
if !errors.As(err, &importError) {
t.Fatal("got import that is not ImportError")
}
}

func TestParseFilterFuncError(t *testing.T) {
type testCase struct {
src string
Expand Down