{"id":"307b8ef3e865721f","repo":"stretchr/testify","slug":"assert-arguments-wrong-number-of-arguments-passe","errorCode":null,"errorMessage":"assert: arguments: Wrong number of arguments passed to String.  Must be 0 or 1, not %d","messagePattern":"assert: arguments: Wrong number of arguments passed to String\\.  Must be 0 or 1, not (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mock/mock.go","lineNumber":1108,"sourceCode":"\tif len(indexOrNil) == 0 {\n\t\t// normal String() method - return a string representation of the args\n\t\tvar argsStr []string\n\t\tfor _, arg := range args {\n\t\t\targsStr = append(argsStr, fmt.Sprintf(\"%T\", arg)) // handles nil nicely\n\t\t}\n\t\treturn strings.Join(argsStr, \",\")\n\t} else if len(indexOrNil) == 1 {\n\t\t// Index has been specified - get the argument at that index\n\t\tindex := indexOrNil[0]\n\t\tvar s string\n\t\tvar ok bool\n\t\tif s, ok = args.Get(index).(string); !ok {\n\t\t\tpanic(fmt.Sprintf(\"assert: arguments: String(%d) failed because object wasn't correct type: %s\", index, args.Get(index)))\n\t\t}\n\t\treturn s\n\t}\n\n\tpanic(fmt.Sprintf(\"assert: arguments: Wrong number of arguments passed to String.  Must be 0 or 1, not %d\", len(indexOrNil)))\n}\n\n// Int gets the argument at the specified index. Panics if there is no argument, or\n// if the argument is of the wrong type.\nfunc (args Arguments) Int(index int) int {\n\tvar s int\n\tvar ok bool\n\tif s, ok = args.Get(index).(int); !ok {\n\t\tpanic(fmt.Sprintf(\"assert: arguments: Int(%d) failed because object wasn't correct type: %v\", index, args.Get(index)))\n\t}\n\treturn s\n}\n\n// Error gets the argument at the specified index. Panics if there is no argument, or\n// if the argument is of the wrong type.\nfunc (args Arguments) Error(index int) error {\n\tobj := args.Get(index)\n\tvar s error","sourceCodeStart":1090,"sourceCodeEnd":1126,"githubUrl":"https://github.com/stretchr/testify/blob/001eb7946baf451879253643e4ce4b38eaa0d4a7/mock/mock.go#L1090-L1126","documentation":"Panicked by Arguments.String() (mock/mock.go:1089) when called with a number of variadic int arguments other than 0 or 1. With zero args it returns a comma-joined type representation of all args; with one arg it extracts the string at that index; any other count is a misuse.","triggerScenarios":"Calling args.String(0, 1) or args.String(1, 2, 3) — passing multiple indices. Typically a typo or misunderstanding that String takes at most one index.","commonSituations":"Confusing Arguments.String with a method that joins multiple indices; copy-paste from code that intended a different accessor.","solutions":["Pass at most one index: args.String(0) to extract, or args.String() for the full representation.","If you need multiple positional strings, call args.String(0), args.String(1), ... separately.","Use args.Get(i).(string) in a loop if you need to extract many."],"exampleFix":"// before\nparts := args.String(0, 1) // panic\n// after\na := args.String(0)\nb := args.String(1)","handlingStrategy":"validation","validationCode":"func validStringArity(n int) bool { return n == 0 || n == 1 }\n// before args.String(idxs...): assert.True(t, validStringArity(len(idxs)))","typeGuard":"func validStringArity(n int) bool { return n == 0 || n == 1 }","tryCatchPattern":"// Enforce the 0-or-1 contract at the call site:\nswitch len(idxs) {\ncase 0: s = args.String()\ncase 1: s = args.String(idxs[0])\ndefault: panic(\"String takes 0 or 1 index\")\n}","preventionTips":["Always call args.String() or args.String(i) with a literal index.","Review code that builds variadic int slices for String."],"tags":["mock","panic","arguments","arity","string"],"analyzedSha":"001eb7946baf451879253643e4ce4b38eaa0d4a7","analyzedAt":"2026-08-04T21:49:58.715Z","schemaVersion":2}