valyala/fasthttp · warning

fasthttp: no args value for the given key

Error message

fasthttp: no args value for the given key

What it means

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.

Source

Thrown at args.go:316

}

// PeekMultiBytes returns all the arg values for the given key.
func (a *Args) PeekMultiBytes(key []byte) [][]byte {
	return a.PeekMulti(b2s(key))
}

// Has returns true if the given key exists in Args.
func (a *Args) Has(key string) bool {
	return hasArg(a.args, key)
}

// HasBytes returns true if the given key exists in Args.
func (a *Args) HasBytes(key []byte) bool {
	return hasArg(a.args, b2s(key))
}

// ErrNoArgValue is returned when Args value with the given key is missing.
var ErrNoArgValue = errors.New("fasthttp: no args value for the given key")

// GetUint returns uint value for the given key.
func (a *Args) GetUint(key string) (int, error) {
	value := a.Peek(key)
	if len(value) == 0 {
		return -1, ErrNoArgValue
	}
	return ParseUint(value)
}

// SetUint sets uint value for the given key.
func (a *Args) SetUint(key string, value int) {
	a.buf = AppendUint(a.buf[:0], value)
	a.SetBytesV(key, a.buf)
}

// SetUintBytes sets uint value for the given key.
func (a *Args) SetUintBytes(key []byte, value int) {

View on GitHub (pinned to c96f600972)

Solutions

  1. 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.
  2. Use errors.Is(err, fasthttp.ErrNoArgValue) to branch on the missing-key case instead of treating it as an unexpected failure.
  3. Verify the client actually sends the parameter (check the full RequestURI / logs) and align parameter names.
  4. For empty-string-is-acceptable cases, read the raw string with args.Peek(key) and parse it yourself.

Example fix

// before
n, err := args.GetUint("page")
if err != nil { return err }
// after
page := 1
if args.Has("page") {
    p, err := args.GetUint("page")
    if err != nil { return err }
    page = p
}
Defensive patterns

Strategy: validation

Validate before calling

func argUint(args *fasthttp.Args, key string, def int) (int, error) {
    if !args.Has(key) {
        return def, nil // treat missing as default
    }
    return args.GetUint(key)
}

Type guard

func hasArgValue(args *fasthttp.Args, key string) bool {
    return len(args.Peek(key)) > 0
}

Try / catch

n, err := args.GetUint("page")
if err != nil {
    if errors.Is(err, fasthttp.ErrNoArgValue) {
        n = defaultPage
    } else {
        return err
    }
}

Prevention

When it happens

Trigger: 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=).

Common situations: 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.

Related errors


AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31). Data as JSON: /api/errors/1cdf66d2819a15cd. Report an issue: GitHub.