{"record":{"id":"1cdf66d2819a15cd","repo":"valyala/fasthttp","slug":"fasthttp-no-args-value-for-the-given-key","errorCode":null,"errorMessage":"fasthttp: no args value for the given key","messagePattern":"fasthttp: no args value for the given key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"args.go","lineNumber":316,"sourceCode":"}\n\n// PeekMultiBytes returns all the arg values for the given key.\nfunc (a *Args) PeekMultiBytes(key []byte) [][]byte {\n\treturn a.PeekMulti(b2s(key))\n}\n\n// Has returns true if the given key exists in Args.\nfunc (a *Args) Has(key string) bool {\n\treturn hasArg(a.args, key)\n}\n\n// HasBytes returns true if the given key exists in Args.\nfunc (a *Args) HasBytes(key []byte) bool {\n\treturn hasArg(a.args, b2s(key))\n}\n\n// ErrNoArgValue is returned when Args value with the given key is missing.\nvar ErrNoArgValue = errors.New(\"fasthttp: no args value for the given key\")\n\n// GetUint returns uint value for the given key.\nfunc (a *Args) GetUint(key string) (int, error) {\n\tvalue := a.Peek(key)\n\tif len(value) == 0 {\n\t\treturn -1, ErrNoArgValue\n\t}\n\treturn ParseUint(value)\n}\n\n// SetUint sets uint value for the given key.\nfunc (a *Args) SetUint(key string, value int) {\n\ta.buf = AppendUint(a.buf[:0], value)\n\ta.SetBytesV(key, a.buf)\n}\n\n// SetUintBytes sets uint value for the given key.\nfunc (a *Args) SetUintBytes(key []byte, value int) {","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/args.go#L298-L334","documentation":"ErrNoArgValue is returned by Args convenience getters (GetUint, GetUfloat) when the requested key is absent from the query string or form body, or when its value is empty. Peek returns a zero-length slice for both missing keys and empty values, so the getter cannot distinguish them and reports ErrNoArgValue. It is a sentinel error (errors.Is-comparable) so callers can detect 'key not found' specifically.","triggerScenarios":"args.GetUint(\"missingKey\") or args.GetUfloat(\"k\") on an Args built from a request whose query string/posted form does not contain that key, or contains it with an empty value (e.g. ?k=).","commonSituations":"Reading optional query parameters that clients omit; a renamed query parameter between client and server versions; form posted without the expected field; trailing '&' or bare 'key=' in a URL.","solutions":["Before calling GetUint/GetUfloat, check presence with args.Has(key) or args.Peek(key) and treat a missing key as a default value or a controlled 400 response.","Use errors.Is(err, fasthttp.ErrNoArgValue) to branch on the missing-key case instead of treating it as an unexpected failure.","Verify the client actually sends the parameter (check the full RequestURI / logs) and align parameter names.","For empty-string-is-acceptable cases, read the raw string with args.Peek(key) and parse it yourself."],"exampleFix":"// before\nn, err := args.GetUint(\"page\")\nif err != nil { return err }\n// after\npage := 1\nif args.Has(\"page\") {\n    p, err := args.GetUint(\"page\")\n    if err != nil { return err }\n    page = p\n}","handlingStrategy":"validation","validationCode":"func argUint(args *fasthttp.Args, key string, def int) (int, error) {\n    if !args.Has(key) {\n        return def, nil // treat missing as default\n    }\n    return args.GetUint(key)\n}","typeGuard":"func hasArgValue(args *fasthttp.Args, key string) bool {\n    return len(args.Peek(key)) > 0\n}","tryCatchPattern":"n, err := args.GetUint(\"page\")\nif err != nil {\n    if errors.Is(err, fasthttp.ErrNoArgValue) {\n        n = defaultPage\n    } else {\n        return err\n    }\n}","preventionTips":["Always check args.Has(key) before typed getters","Decide explicitly whether a missing parameter is an error or a default","Log the full RequestURI when the parameter is unexpectedly absent","Align client/server parameter names in a shared constant"],"tags":["query-params","input-validation","fasthttp"],"backgroundTag":"missing-query-parameter","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}