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

Why the type of failpoint.Value can't be string #62

Open
SmartMalphite opened this issue Oct 12, 2020 · 2 comments
Open

Why the type of failpoint.Value can't be string #62

SmartMalphite opened this issue Oct 12, 2020 · 2 comments
Labels
question Further information is requested

Comments

@SmartMalphite
Copy link

the definition in the source code about Value's type in "github.com/pingcap/failpoint/failpoint.go"

	// Value represents value that retrieved from failpoint terms.
	// It can be used as following types:
	// 1. val.(int)      // GO_FAILPOINTS="failpoint-name=return(1)"
	// 2. val.(string)   // GO_FAILPOINTS="failpoint-name=return('1')"
	// 3. val.(bool)     // GO_FAILPOINTS="failpoint-name=return(true)"
	Value interface{}

but in my code

failpoint.Inject("demoPanic", func(val failpoint.Value) {
		fmt.Println(val)
		fmt.Println(val.(string))
}

and start my progrom with cmd:
GO_FAILPOINTS="mypackagename/demoPanic=return('100')" ./beego-backend
An exception was thrown
[panic.go:522] Handler crashed with error interface conversion: failpoint.Value is bool, not string ···

@SmartMalphite SmartMalphite added the question Further information is requested label Oct 12, 2020
@amyangfei
Copy link
Contributor

ref to: #61

Should use either GO_FAILPOINTS="mypackagename/demoPanic=return(\"100\")" or GO_FAILPOINTS='mypackagename/demoPanic=return("100")'

@jinjiaKarl
Copy link

// add.go
func add(ctx context.Context) string {
     failpoint.InjectContext(ctx, "failpoint-name1", func(value failpoint.Value) string {
         failpoint.Return(value.(string))
     })

     return "1"
 }
// add_test.go
 func TestAdd(t *testing.T) {
     err := failpoint.Enable("golangtest/gofailpoint/failpoint-name1", "return('0.01')")
     if err != nil {
         log.Fatal(err)
     }
failpoints := map[string]struct{}{
         "golangtest/gofailpoint/failpoint-name1": {},
     }
     ctx := failpoint.WithHook(context.Background(), func(ctx context.Context, fpname string) bool {
         _, found := failpoints[fpname]
         return found
     })
     log.Println(add(ctx))
 }

when I execute my program, it truns out that:

error on golangtest/gofailpoint/failpoint-name1: failpoint: failed to parse "return('0.01')" past ")"

how come does not it support "return('0.01')" of this pattern?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants