{"id":"f1639225b2c2af80","repo":"stretchr/testify","slug":"assert-arguments-s-does-not-return-a-bool","errorCode":null,"errorMessage":"assert: arguments: %s does not return a bool","messagePattern":"assert: arguments: (.+?) does not return a bool","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mock/mock.go","lineNumber":931,"sourceCode":"//\n// Example:\n//\n//\tm.On(\"Do\", MatchedBy(func(req *http.Request) bool { return req.Host == \"example.com\" }))\n//\n// fn must be a function accepting a single argument (of the expected type)\n// which returns a bool. If fn doesn't match the required signature,\n// MatchedBy() panics.\nfunc MatchedBy(fn interface{}) argumentMatcher {\n\tfnType := reflect.TypeOf(fn)\n\n\tif fnType.Kind() != reflect.Func {\n\t\tpanic(fmt.Sprintf(\"assert: arguments: %s is not a func\", fn))\n\t}\n\tif fnType.NumIn() != 1 {\n\t\tpanic(fmt.Sprintf(\"assert: arguments: %s does not take exactly one argument\", fn))\n\t}\n\tif fnType.NumOut() != 1 || fnType.Out(0).Kind() != reflect.Bool {\n\t\tpanic(fmt.Sprintf(\"assert: arguments: %s does not return a bool\", fn))\n\t}\n\n\treturn argumentMatcher{fn: reflect.ValueOf(fn)}\n}\n\n// Get Returns the argument at the specified index.\nfunc (args Arguments) Get(index int) interface{} {\n\tif index+1 > len(args) {\n\t\tpanic(fmt.Sprintf(\"assert: arguments: Cannot call Get(%d) because there are %d argument(s).\", index, len(args)))\n\t}\n\treturn args[index]\n}\n\n// Is gets whether the objects match the arguments specified.\nfunc (args Arguments) Is(objects ...interface{}) bool {\n\tfor i, obj := range args {\n\t\tif obj != objects[i] {\n\t\t\treturn false","sourceCodeStart":913,"sourceCodeEnd":949,"githubUrl":"https://github.com/stretchr/testify/blob/001eb7946baf451879253643e4ce4b38eaa0d4a7/mock/mock.go#L913-L949","documentation":"Panicked by MatchedBy() (mock/mock.go:921) when the passed function does not return exactly one value of kind Bool. MatchedBy interprets a true/false return as match/no-match, so any other signature is invalid. Check at mock/mock.go:930.","triggerScenarios":"Calling mock.MatchedBy(func(x int) {}) (no return), mock.MatchedBy(func(x int) error { ... }) (wrong return type), or mock.MatchedBy(func(x int) (bool, error) { ... }) (two returns).","commonSituations":"Reusing an existing validation function that returns an error as a matcher; forgetting the bool return after refactoring; copying a predicate that returns a custom Result type.","solutions":["Make the matcher return a single bool: mock.MatchedBy(func(x T) bool { ... }).","Wrap an error-returning validator: mock.MatchedBy(func(x T) bool { return validator(x) == nil }).","If your check returns (bool, error), collapse it to bool by ignoring or failing on the error inside the matcher."],"exampleFix":"// before\nm.On(\"Do\", mock.MatchedBy(func(x int) error { return validate(x) })).Return(nil)\n// after\nm.On(\"Do\", mock.MatchedBy(func(x int) bool { return validate(x) == nil })).Return(nil)","handlingStrategy":"validation","validationCode":"func returnsBool(fn interface{}) bool {\n    t := reflect.TypeOf(fn)\n    return t != nil && t.Kind() == reflect.Func && t.NumOut() == 1 && t.Out(0).Kind() == reflect.Bool\n}\n// before MatchedBy: assert.True(t, returnsBool(matcher))","typeGuard":"func matcherReturnsBool(fn interface{}) bool {\n    t := reflect.TypeOf(fn)\n    return t != nil && t.Kind() == reflect.Func && t.NumOut() == 1 && t.Out(0).Kind() == reflect.Bool\n}","tryCatchPattern":"// Validate return signature before constructing:\nif !matcherReturnsBool(matcher) {\n    log.Fatal(\"matcher must return a single bool\")\n}\nm.On(\"Do\", mock.MatchedBy(matcher))","preventionTips":["Always write matchers as func(T) bool; codify with a generic helper.","Lint for MatchedBy predicates whose return type isn't bool."],"tags":["mock","panic","matchedby","return-type","bool"],"analyzedSha":"001eb7946baf451879253643e4ce4b38eaa0d4a7","analyzedAt":"2026-08-04T21:49:58.715Z","schemaVersion":2}