{"record":{"id":"20d5ca2c3c6d51f1","repo":"valyala/fasthttp","slug":"empty-integer","errorCode":null,"errorMessage":"empty integer","messagePattern":"empty integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bytesconv.go","lineNumber":275,"sourceCode":"\n\treturn strconv.AppendUint(dst, uint64(n), 10)\n}\n\n// ParseUint parses uint from buf.\n//\n// A value too large for an int is an error rather than a wrapped result, so\n// ParseUint accepts exactly the unsigned decimal strings whose value fits in an\n// int on the current platform.\nfunc ParseUint(buf []byte) (int, error) {\n\tv, n, err := parseUintBuf(buf)\n\tif n != len(buf) {\n\t\treturn -1, errUnexpectedTrailingChar\n\t}\n\treturn v, err\n}\n\nvar (\n\terrEmptyInt               = errors.New(\"empty integer\")\n\terrIPv4PartTooLarge       = errors.New(\"ip part cannot exceed 255\")\n\terrUnexpectedFirstChar    = errors.New(\"unexpected first char found: expecting 0-9\")\n\terrUnexpectedTrailingChar = errors.New(\"unexpected trailing char found: expecting 0-9\")\n\terrTooLongInt             = errors.New(\"too long int\")\n)\n\nconst (\n\t// maxIntDiv10 is the largest accumulator that can still take another digit.\n\t// Anything above it overflows an int when multiplied by 10.\n\tmaxIntDiv10 = math.MaxInt / 10\n\n\t// maxSafeIntDigits is how many leading decimal digits can never overflow an\n\t// int, whatever the word size: 10**18-1 fits a 64-bit int and 10**9-1 fits a\n\t// 32-bit one. Go defines strconv.IntSize as 32 or 64 and nothing else.\n\t// TestMaxSafeIntDigits checks both halves of that claim on the build's own\n\t// int size.\n\tmaxSafeIntDigits = 9 * (strconv.IntSize / 32)\n)","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/bytesconv.go#L257-L293","documentation":"errEmptyInt is returned by parseUintBuf (used by ParseUint and integer Args getters) when the input buffer contains no digits at all. Since there is nothing to parse, the function returns -1 and this sentinel error. Callers hitting it passed an empty or digit-less string where an unsigned integer was expected.","triggerScenarios":"fasthttp.ParseUint(nil) or ParseUint([]byte(\"\")); args.GetUint on a key whose value is empty; parsing a header like Content-Length that arrived empty.","commonSituations":"Optional numeric query parameters the client omitted; headers stripped by a proxy; config values that are empty strings rather than unset.","solutions":["Guard with len(buf) == 0 before calling ParseUint and apply a default or return a clearer error.","Use errors.Is(err, ...) to distinguish 'empty' from other parse failures (first/trailing char, too long).","Validate the raw string with a quick regexp like ^[0-9]+$ when input shape is uncertain.","For Args, check args.Has(key) first so a missing key and an empty value are handled separately."],"exampleFix":"// before\nn, err := fasthttp.ParseUint(b)\n// after\nif len(b) == 0 {\n    return 0, errors.New(\"numeric field is empty\")\n}\nn, err := fasthttp.ParseUint(b)","handlingStrategy":"validation","validationCode":"func parseUintNonEmpty(b []byte) (int, error) {\n    if len(b) == 0 {\n        return 0, errors.New(\"numeric value required\")\n    }\n    return fasthttp.ParseUint(b)\n}","typeGuard":"func digitsOnly(b []byte) bool {\n    return len(b) > 0 && bytes.IndexFunc(b, func(r rune) bool { return r < '0' || r > '9' }) < 0\n}","tryCatchPattern":"n, err := fasthttp.ParseUint(b)\nif err != nil {\n    if err.Error() == \"empty integer\" {\n        return 0, errors.New(\"field must not be empty\")\n    }\n    return err\n}","preventionTips":["Apply defaults for optional numeric fields before parsing","Check len(b) > 0 whenever input may be nil","Distinguish missing keys from empty values when reading Args","Validate numeric headers with a digits-only check"],"tags":["integer-parsing","empty-input","input-validation"],"backgroundTag":"empty-input-value","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}