stretchr/testify · error
assert: arguments: Wrong number of arguments passed to Strin
Error message
assert: arguments: Wrong number of arguments passed to String. Must be 0 or 1, not %d
What it means
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.
Source
Thrown at mock/mock.go:1108
if len(indexOrNil) == 0 {
// normal String() method - return a string representation of the args
var argsStr []string
for _, arg := range args {
argsStr = append(argsStr, fmt.Sprintf("%T", arg)) // handles nil nicely
}
return strings.Join(argsStr, ",")
} else if len(indexOrNil) == 1 {
// Index has been specified - get the argument at that index
index := indexOrNil[0]
var s string
var ok bool
if s, ok = args.Get(index).(string); !ok {
panic(fmt.Sprintf("assert: arguments: String(%d) failed because object wasn't correct type: %s", index, args.Get(index)))
}
return s
}
panic(fmt.Sprintf("assert: arguments: Wrong number of arguments passed to String. Must be 0 or 1, not %d", len(indexOrNil)))
}
// Int gets the argument at the specified index. Panics if there is no argument, or
// if the argument is of the wrong type.
func (args Arguments) Int(index int) int {
var s int
var ok bool
if s, ok = args.Get(index).(int); !ok {
panic(fmt.Sprintf("assert: arguments: Int(%d) failed because object wasn't correct type: %v", index, args.Get(index)))
}
return s
}
// Error gets the argument at the specified index. Panics if there is no argument, or
// if the argument is of the wrong type.
func (args Arguments) Error(index int) error {
obj := args.Get(index)
var s errorView on GitHub (pinned to 001eb7946b)
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.
Example fix
// before parts := args.String(0, 1) // panic // after a := args.String(0) b := args.String(1)
Defensive patterns
Strategy: validation
Validate before calling
func validStringArity(n int) bool { return n == 0 || n == 1 }
// before args.String(idxs...): assert.True(t, validStringArity(len(idxs))) Type guard
func validStringArity(n int) bool { return n == 0 || n == 1 } Try / catch
// Enforce the 0-or-1 contract at the call site:
switch len(idxs) {
case 0: s = args.String()
case 1: s = args.String(idxs[0])
default: panic("String takes 0 or 1 index")
} Prevention
- Always call args.String() or args.String(i) with a literal index.
- Review code that builds variadic int slices for String.
When it happens
Trigger: 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.
Common situations: Confusing Arguments.String with a method that joins multiple indices; copy-paste from code that intended a different accessor.
Related errors
- assert: arguments: String(%d) failed because object wasn't c
- assert: arguments: %s does not take exactly one argument
- assert: arguments: Cannot call Get(%d) because there are %d
- assert: arguments: Int(%d) failed because object wasn't corr
- assert: arguments: Error(%d) failed because object wasn't co
AI-assisted analysis of stretchr/testify@001eb7946b (2026-08-04).
Data as JSON: /data/errors/307b8ef3e865721f.json.
Report an issue: GitHub.