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 panics when Suggest'ing one + N arguments #192

Closed
tdakkota opened this issue Jan 25, 2021 · 1 comment · Fixed by #211
Closed

ruleguard panics when Suggest'ing one + N arguments #192

tdakkota opened this issue Jan 25, 2021 · 1 comment · Fixed by #211
Assignees
Labels
bug Something isn't working

Comments

@tdakkota
Copy link

To reproduce

func BadRule(m dsl.Matcher) {
	m.Match("fmt.$method($arg, $*args)").Suggest("log.$method($arg, $args)")
}
Original rule for zap
package gorules

import (
  "github.com/quasilyte/go-ruleguard/dsl"
)

func ZapPreferNoWith(m dsl.Matcher) {
  m.Import("go.uber.org/zap")

  m.Match("$l.With($arg, $*args).$method($*msg_args)").Where(
  	m["l"].Type.Is("*zap.Logger") &&
  		m["method"].Text.Matches("Debug|Info|Warn|Error|DPanic|Panic|Fatal"),
  ).Suggest("$l.$method($msg_args, $arg, $args)")
}
Partial stacktrace
panic: runtime error: index out of range [0] with length 0

goroutine 3525 [running]:
github.com/quasilyte/go-ruleguard/internal/mvdan.cc/gogrep.exprList.Pos(...)
        C:/Users/tdakkota/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.3.1-0.20210125091851-f953b71a3ba3/internal/mvdan.cc/gogrep/match.go:1098
github.com/quasilyte/go-ruleguard/ruleguard.(*rulesRunner).nodeText(0xc010f1ab00, 0x509720, 0xc010d87ea0, 0x5, 0x34, 0xc00b7a8990)
        C:/Users/tdakkota/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.3.1-0.20210125091851-f953b71a3ba3/ruleguard/runner.go:57 +0x65
github.com/quasilyte/go-ruleguard/ruleguard.(*rulesRunner).renderMessage(0xc010f1ab00, 0xc0006836b0, 0x2e, 0x5083a0, 0xc00b7afd00, 0xc010f2cea0, 0xc010f1ab01, 0x508c60, 0x387888)
        C:/Users/tdakkota/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.3.1-0.20210125091851-f953b71a3ba3/ruleguard/runner.go:232 +0x472
github.com/quasilyte/go-ruleguard/ruleguard.(*rulesRunner).handleMatch(0xc010f1ab00, 0xc00b399f80, 0xf, 0xc0000a0160, 0x12, 0x14, 0xc010d87e20, 0xc0006836b0, 0x2e, 0x0, ...)
        C:/Users/tdakkota/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.3.1-0.20210125091851-f953b71a3ba3/ruleguard/runner.go:174 +0xf4
github.com/quasilyte/go-ruleguard/ruleguard.(*rulesRunner).run.func2.1(0x5083a0, 0xc00b7afd00, 0xc010f2cea0)
        C:/Users/tdakkota/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.3.1-0.20210125091851-f953b71a3ba3/ruleguard/runner.go:107 +0xe8
github.com/quasilyte/go-ruleguard/internal/mvdan.cc/gogrep.(*Pattern).MatchNode(0xc010d87e20, 0x5083a0, 0xc00b7afd00, 0xc00b7a8d78)
        C:/Users/tdakkota/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.3.1-0.20210125091851-f953b71a3ba3/internal/mvdan.cc/gogrep/kludge.go:50 +0xbb
github.com/quasilyte/go-ruleguard/ruleguard.(*rulesRunner).run.func2(0x5083a0, 0xc00b7afd00, 0x508801)
        C:/Users/tdakkota/go/pkg/mod/github.com/quasilyte/go-ruleguard@v0.3.1-0.20210125091851-f953b71a3ba3/ruleguard/runner.go:106 +0x19f
go/ast.inspector.Visit(0xc010de2c40, 0x5083a0, 0xc00b7afd00, 0x5069c0, 0xc010de2c40)
        c:/go/src/go/ast/walk.go:373 +0x42
@quasilyte quasilyte added the bug Something isn't working label Jan 25, 2021
@quasilyte quasilyte self-assigned this Jan 25, 2021
@quasilyte
Copy link
Owner

It's simple to fix a panic, but a proper solution would require some changes to the gogrep.
I'll see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants