{"id":"943e174ef290be76","repo":"stretchr/testify","slug":"assert-arguments-int-d-failed-because-object-w","errorCode":null,"errorMessage":"assert: arguments: Int(%d) failed because object wasn't correct type: %v","messagePattern":"assert: arguments: Int\\((.+?)\\) failed because object wasn't correct type: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mock/mock.go","lineNumber":1117,"sourceCode":"\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\n\tvar ok bool\n\tif obj == nil {\n\t\treturn nil\n\t}\n\tif s, ok = obj.(error); !ok {\n\t\tpanic(fmt.Sprintf(\"assert: arguments: Error(%d) failed because object wasn't correct type: %v\", index, obj))\n\t}\n\treturn s\n}","sourceCodeStart":1099,"sourceCodeEnd":1135,"githubUrl":"https://github.com/stretchr/testify/blob/001eb7946baf451879253643e4ce4b38eaa0d4a7/mock/mock.go#L1099-L1135","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nid := args.Int(0) // arg is int64\n// after\nid := int(args.Get(0).(int64))","handlingStrategy":"type-guard","validationCode":"func argIsInt(args mock.Arguments, i int) bool {\n    if i >= len(args) { return false }\n    _, ok := args.Get(i).(int)\n    return ok\n}\n// before args.Int(i): if !argIsInt(args, i) { t.Fatalf(\"arg %d not int\", i) }","typeGuard":"func argIsInt(args mock.Arguments, i int) bool {\n    if i >= len(args) { return false }\n    _, ok := args.Get(i).(int)\n    return ok\n}","tryCatchPattern":"// Use a type switch covering all integer kinds:\nswitch v := args.Get(i).(type) {\ncase int: n = v\ncase int64: n = int(v)\ncase int32: n = int(v)\ndefault: t.Fatalf(\"unexpected type %T\", v)\n}","preventionTips":["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."],"tags":["mock","panic","arguments","type-assertion","int"],"analyzedSha":"001eb7946baf451879253643e4ce4b38eaa0d4a7","analyzedAt":"2026-08-04T21:49:58.715Z","schemaVersion":2}