{"record":{"id":"9aebd6824b4cb55b","repo":"nats-io/nats-server","slug":"expected-integer-but-got-s","errorCode":null,"errorMessage":"expected integer, but got '%s'","messagePattern":"expected integer, but got '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"conf/parse.go","lineNumber":316,"sourceCode":"\tcase itemString:\n\t\t// FIXME(dlc) sanitize string?\n\t\tsetValue(it, it.val)\n\tcase itemInteger:\n\t\tlastDigit := 0\n\t\tfor _, r := range it.val {\n\t\t\tif !unicode.IsDigit(r) && r != '-' {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tlastDigit++\n\t\t}\n\t\tnumStr := it.val[:lastDigit]\n\t\tnum, err := strconv.ParseInt(numStr, 10, 64)\n\t\tif err != nil {\n\t\t\tif e, ok := err.(*strconv.NumError); ok &&\n\t\t\t\te.Err == strconv.ErrRange {\n\t\t\t\treturn fmt.Errorf(\"integer '%s' is out of the range\", it.val)\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"expected integer, but got '%s'\", it.val)\n\t\t}\n\t\t// Process a suffix\n\t\tsuffix := strings.ToLower(strings.TrimSpace(it.val[lastDigit:]))\n\n\t\tswitch suffix {\n\t\tcase \"\":\n\t\t\tsetValue(it, num)\n\t\tcase \"k\":\n\t\t\tsetValue(it, num*1000)\n\t\tcase \"kb\", \"ki\", \"kib\":\n\t\t\tsetValue(it, num*1024)\n\t\tcase \"m\":\n\t\t\tsetValue(it, num*1000*1000)\n\t\tcase \"mb\", \"mi\", \"mib\":\n\t\t\tsetValue(it, num*1024*1024)\n\t\tcase \"g\":\n\t\t\tsetValue(it, num*1000*1000*1000)\n\t\tcase \"gb\", \"gi\", \"gib\":","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/conf/parse.go#L298-L334","documentation":"In processItem's numeric handling, if strconv.ParseInt fails with anything other than ErrRange (i.e. the token is not a valid integer at all), the parser returns \"expected integer, but got '%s'\". The library throws it when a config option requires a number but receives non-numeric text.","triggerScenarios":"A numeric option given a string or malformed value, e.g. `port: \"4222x\"`, `max_payload: abc`, or a value containing spaces/underscores like `1 024`; the digit-prefix parse of the token fails with a non-range error.","commonSituations":"Typo in numeric values; quoting numbers with stray characters; env-var interpolation producing empty or non-numeric text; copy/paste inserting invisible characters into numbers.","solutions":["Fix the value at the reported location to be a plain integer (e.g. port: 4222)","Remove quotes, spaces, underscores or units from numeric-only options","Verify env substitutions ($VAR) expand to valid numbers","Run `nats-server -t -c file.conf` to catch it before startup"],"exampleFix":"// before\nport: \"4222x\"\n// after\nport: 4222","handlingStrategy":"validation","validationCode":"func isPlainInteger(s string) bool {\n    s = strings.TrimSpace(s)\n    if s == \"\" { return false }\n    _, err := strconv.ParseInt(s, 10, 64)\n    return err == nil\n}\n// apply to every numeric option value before parsing","typeGuard":null,"tryCatchPattern":"cfg, err := conf.ParseFile(fp)\nif err != nil {\n    if strings.Contains(err.Error(), \"expected integer, but got\") {\n        log.Fatalf(\"numeric option has non-numeric value in %s: %v\", fp, err)\n    }\n    return err\n}","preventionTips":["Keep numeric options unquoted and free of units/spaces","Validate env-var substitutions resolve to numbers","Strip invisible characters when copying values between editors","Gate deploys on nats-server -t config validation"],"tags":["config","type-error","parser","nats-server"],"backgroundTag":"config-type-mismatch","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}