{"record":{"id":"14212eb2803346b6","repo":"dgraph-io/dgraph","slug":"error-unable-to-parse-cache-percentage-s","errorCode":null,"errorMessage":"ERROR: unable to parse cache percentage(%s)","messagePattern":"ERROR: unable to parse cache percentage\\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/x.go","lineNumber":1397,"sourceCode":"\treturn aCopy\n}\n\n// GetCachePercentages returns the slice of cache percentages given the \",\" (comma) separated\n// cache percentages(integers) string and expected number of caches.\nfunc GetCachePercentages(cpString string, numExpected int) ([]int64, error) {\n\tcp := strings.Split(cpString, \",\")\n\t// Sanity checks\n\tif len(cp) != numExpected {\n\t\treturn nil, errors.Errorf(\"ERROR: expected %d cache percentages, got %d\",\n\t\t\tnumExpected, len(cp))\n\t}\n\n\tvar cachePercent []int64\n\tpercentSum := 0\n\tfor _, percent := range cp {\n\t\tx, err := strconv.Atoi(percent)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Errorf(\"ERROR: unable to parse cache percentage(%s)\", percent)\n\t\t}\n\t\tif x < 0 {\n\t\t\treturn nil, errors.Errorf(\"ERROR: cache percentage(%s) cannot be negative\", percent)\n\t\t}\n\t\tcachePercent = append(cachePercent, int64(x))\n\t\tpercentSum += x\n\t}\n\n\tif percentSum != 100 {\n\t\treturn nil, errors.Errorf(\"ERROR: cache percentages (%s) does not sum up to 100\",\n\t\t\tstrings.Join(cp, \"+\"))\n\t}\n\n\treturn cachePercent, nil\n}\n\n// ParseCompression returns badger.compressionType and compression level given compression string\n// of format compression-type:compression-level","sourceCodeStart":1379,"sourceCodeEnd":1415,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/x.go#L1379-L1415","documentation":"Each comma-separated element of the cache percentage string must parse as an integer via strconv.Atoi. When an element is not a valid integer, GetCachePercentages returns this error naming the offending element.","triggerScenarios":"Calling GetCachePercentages with a string containing a non-numeric item, e.g. \"50,abc\" or values with units/spaces like \"50 %,50\".","commonSituations":"Typo'd config values, pasting percentages with '%' or spaces, decimal values like '33.3' (not integers), or locale-formatted numbers.","solutions":["Ensure every comma-separated value is a plain non-negative integer (e.g. \"50,50\")","Remove units, spaces, or decimals from the cache percentage config","Validate the string by splitting on ',' and strconv.Atoi-ing each item before calling"],"exampleFix":"// before\ncp, err := GetCachePercentages(\"50 %,50\", 2) // unparsable \"50 %\"\n// after\ncp, err := GetCachePercentages(\"50,50\", 2)","handlingStrategy":"validation","validationCode":"func validCachePctString(cpString string) bool {\n    for _, p := range strings.Split(cpString, \",\") {\n        if _, err := strconv.Atoi(strings.TrimSpace(p)); err != nil { return false }\n    }\n    return true\n}","typeGuard":"func isParsablePercent(s string) bool { _, err := strconv.Atoi(strings.TrimSpace(s)); return err == nil }","tryCatchPattern":null,"preventionTips":["Store cache percentages as plain integers without '%' or spaces","Trim whitespace on each CSV element before parsing","Use typed config (list of ints) instead of raw strings where possible"],"tags":["configuration","cache","parsing"],"backgroundTag":"invalid-integer-config","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}