failpoint doesn't work if the marker function is defined in the main package
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 895
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Bug Report
Please answer these questions before submitting your issue. Thanks!
- What did you do? If possible, provide a recipe for reproducing the error.
For example, we have a file named main.go:
package main
import (
"github.com/pingcap/failpoint"
)
func F1(name string) string {
failpoint.Inject("failpoint-name", nil)
return "hello " + name
}
func main() {
failpoint.Enable("failpoint-name", "panic")
F1("ttt")
}
After transfrom the code with failpoint-ctl enable, the generated binding__failpoint_binding__.go looks like this:
package main
import "reflect"
type __failpointBindingType struct {pkgpath string}
var __failpointBindingCache = &__failpointBindingType{}
func init() {
__failpointBindingCache.pkgpath = reflect.TypeOf(__failpointBindingType{}).PkgPath()
}
func _curpkg_(name string) string {
return __failpointBindingCache.pkgpath + "/" + name
}
You may notice that binding__failpoint_binding__.go is also in package main, that means binding__failpoint_binding__.go could not be found by main.go.
Run go run main.go then, you will find the following error:
./main.go:8:17: undefined: _curpkg_
- What did you expect to see?
program panics due to failpoint
- What did you see instead?
./main.go:8:17: undefined: _curpkg_
- Versions of the failpoint
$ ./bin/failpoint-ctl -V
ReleaseVersion bf45ab2
BuildTS 2019-05-15 09:48:44
GitHash bf45ab20bfc48d624b61944a4820768c16d7db99
GitBranch master
GoVersion go version go1.12 darwin/amd64
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with main.go and the generated binding__failpoint_binding__.go after running failpoint-ctl enable. Reproduce with go run main.go and inspect why the generated curpkg symbol is unavailable. Done means the example compiles and panics when the failpoint is enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100