Skip to content

failpoint doesn't work if the marker function is defined in the main package #33

@spongedu

Description

@spongedu

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. 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_
  1. What did you expect to see?

program panics due to failpoint

  1. What did you see instead?
 ./main.go:8:17: undefined: _curpkg_
  1. Versions of the failpoint

$ ./bin/failpoint-ctl -V
ReleaseVersion bf45ab2
BuildTS 2019-05-15 09:48:44
GitHash bf45ab2
GitBranch master
GoVersion go version go1.12 darwin/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions