{"record":{"id":"b199eacfa9e112e3","repo":"grafana/k6","slug":"unable-to-use-type-t-as-a-duration-value","errorCode":null,"errorMessage":"unable to use type %T as a duration value","messagePattern":"unable to use type %T as a duration value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/types/types.go","lineNumber":189,"sourceCode":"\tcase int32:\n\t\treturn int64(n), nil\n\tcase int64:\n\t\treturn n, nil\n\tcase uint:\n\t\treturn int64(n), nil //nolint:gosec\n\tcase uint8:\n\t\treturn int64(n), nil\n\tcase uint16:\n\t\treturn int64(n), nil\n\tcase uint32:\n\t\treturn int64(n), nil\n\tcase uint64:\n\t\tif n > math.MaxInt64 {\n\t\t\treturn 0, fmt.Errorf(\"%d is too big\", n)\n\t\t}\n\t\treturn int64(n), nil\n\tdefault:\n\t\treturn 0, fmt.Errorf(\"unable to use type %T as a duration value\", v)\n\t}\n}\n\n// GetDurationValue is a helper function that can convert a lot of different\n// types to time.Duration.\n//\n// TODO: move to a separate package and check for integer overflows?\nfunc GetDurationValue(v any) (time.Duration, error) {\n\tswitch d := v.(type) {\n\tcase time.Duration:\n\t\treturn d, nil\n\tcase string:\n\t\treturn ParseExtendedDuration(d)\n\tcase float32:\n\t\treturn time.Duration(float64(d) * float64(time.Millisecond)), nil\n\tcase float64:\n\t\treturn time.Duration(d * float64(time.Millisecond)), nil\n\tdefault:","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/lib/types/types.go#L171-L207","documentation":"Raised by getInt64 (a helper behind GetDurationValue) when the duration option's value is of a Go type the helper does not handle — typically a JavaScript value that could not be narrowed to a numeric or string type. %P-style placeholder reports the actual type.","triggerScenarios":"Thrown at lib/types/types.go:189 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass durations as strings (\"30s\") or numbers","Avoid passing objects, arrays, booleans or null as duration values"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}