{"record":{"id":"4a1e3a87071d3f34","repo":"nats-io/nats-server","slug":"negative-number-d-not-allowed-s","errorCode":null,"errorMessage":"negative number (%d) not allowed: %s","messagePattern":"negative number \\((.+?)\\) not allowed: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cron.go","lineNumber":253,"sourceCode":"\n// parseIntOrName returns the (possibly-named) integer contained in expr.\nfunc parseIntOrName(expr string, names map[string]uint) (uint, error) {\n\tif names != nil {\n\t\tif namedInt, ok := names[strings.ToLower(expr)]; ok {\n\t\t\treturn namedInt, nil\n\t\t}\n\t}\n\treturn mustParseInt(expr)\n}\n\n// mustParseInt parses the given expression as an int or returns an error.\nfunc mustParseInt(expr string) (uint, error) {\n\tnum, err := strconv.Atoi(expr)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to parse int from %s: %s\", expr, err)\n\t}\n\tif num < 0 {\n\t\treturn 0, fmt.Errorf(\"negative number (%d) not allowed: %s\", num, expr)\n\t}\n\treturn uint(num), nil\n}\n\n// getBits sets all bits in the range [min, max], modulo the given step size.\nfunc getBits(min, max, step uint) uint64 {\n\tvar bits uint64\n\n\t// If step is 1, use shifts.\n\tif step == 1 {\n\t\treturn ^(math.MaxUint64 << (max + 1)) & (math.MaxUint64 << min)\n\t}\n\n\t// Else, use a simple loop.\n\tfor i := min; i <= max; i += step {\n\t\tbits |= 1 << i\n\t}\n\treturn bits","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/cron.go#L235-L271","documentation":"Cron expression integer parser: strconv.Atoi succeeded but the value is negative, which no cron field accepts; the offending subexpression is included.","triggerScenarios":"A cron field token starting with '-', e.g. \"-5\", \"1--3\" (second token '-3'), or \"*-5\", reaching mustParseInt via getRange or parseIntOrName in parseCron.","commonSituations":"Accidentally pasting a leading minus; malformed ranges with doubled hyphens; template variables that rendered empty leaving a stray '-' prefix.","solutions":["Remove the minus sign and use the intended non-negative value","Fix doubled hyphens in ranges (\"1-3\", not \"1--3\")","Interpolate template variables before scheduling and validate the rendered expression"],"exampleFix":"// before (minute field)\n expr := \"1--3\"\n// after\n expr := \"1-3\"","handlingStrategy":"validation","validationCode":"func isNonNegativeInt(s string) bool {\n    n, err := strconv.Atoi(s)\n    return err == nil && n >= 0\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip leading '-' signs when interpolating values into cron strings","Reject double hyphens in ranges at config load time"],"tags":["cron","parsing","number-format"],"backgroundTag":"invalid-cron-expression","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}