stretchr/testify · error
assert: arguments: Int(%d) failed because object wasn't corr
Error message
assert: arguments: Int(%d) failed because object wasn't correct type: %v
What it means
Panicked by Arguments.Int(index) (mock/mock.go:1113) when args.Get(index) does not type-assert to the builtin int. The cast is strict: int32, int64, uint, or any other integer kind will NOT match `.(int)` and trigger the panic. Message prints the offending value.
Source
Thrown at mock/mock.go:1117
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 error
var ok bool
if obj == nil {
return nil
}
if s, ok = obj.(error); !ok {
panic(fmt.Sprintf("assert: arguments: Error(%d) failed because object wasn't correct type: %v", index, obj))
}
return s
}View on GitHub (pinned to 001eb7946b)
Solutions
- Extract via the correct type then convert: int(args.Get(i).(int64)).
- Use a type switch in the callback to handle the concrete integer kind.
- Update the mock argument list and extractor together when changing the production signature.
Example fix
// before id := args.Int(0) // arg is int64 // after id := int(args.Get(0).(int64))
Defensive patterns
Strategy: type-guard
Validate before calling
func argIsInt(args mock.Arguments, i int) bool {
if i >= len(args) { return false }
_, ok := args.Get(i).(int)
return ok
}
// before args.Int(i): if !argIsInt(args, i) { t.Fatalf("arg %d not int", i) } Type guard
func argIsInt(args mock.Arguments, i int) bool {
if i >= len(args) { return false }
_, ok := args.Get(i).(int)
return ok
} Try / catch
// Use a type switch covering all integer kinds:
switch v := args.Get(i).(type) {
case int: n = v
case int64: n = int(v)
case int32: n = int(v)
default: t.Fatalf("unexpected type %T", v)
} Prevention
- Prefer type switches over args.Int for cross-package APIs.
- Standardize on int64 internally and convert at the boundary.
- Update extractors when switching integer widths.
When it happens
Trigger: Calling args.Int(0) when the method parameter is int64, int32, uint, or a numeric alias type. Common with protobuf (int32/int64), database/sql (int64 IDs), or bit-sized fields.
Common situations: Cross-package APIs that use sized integers; refactoring a method from int to int64 without updating the test extractor; platform differences where int width varies.
Related errors
- assert: arguments: String(%d) failed because object wasn't c
- assert: arguments: Error(%d) failed because object wasn't co
- assert: arguments: Cannot call Get(%d) because there are %d
- assert: arguments: Wrong number of arguments passed to Strin
- assert: arguments: Bool(%d) failed because object wasn't cor
AI-assisted analysis of stretchr/testify@001eb7946b (2026-08-04).
Data as JSON: /data/errors/943e174ef290be76.json.
Report an issue: GitHub.