{"record":{"id":"f0e731bcbe056f3b","repo":"coredns/coredns","slug":"cache-min-ttl-can-not-be-negative-d","errorCode":null,"errorMessage":"cache min TTL can not be negative: %d","messagePattern":"cache min TTL can not be negative: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/cache/setup.go","lineNumber":100,"sourceCode":"\t\t\t\tca.pcap = pcap\n\t\t\t\tif len(args) > 1 {\n\t\t\t\t\tpttl, err := strconv.Atoi(args[1])\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t}\n\t\t\t\t\t// Reserve 0 (and smaller for future things)\n\t\t\t\t\tif pttl <= 0 {\n\t\t\t\t\t\treturn nil, fmt.Errorf(\"cache TTL can not be zero or negative: %d\", pttl)\n\t\t\t\t\t}\n\t\t\t\t\tca.pttl = time.Duration(pttl) * time.Second\n\t\t\t\t\tif len(args) > 2 {\n\t\t\t\t\t\tminpttl, err := strconv.Atoi(args[2])\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn nil, err\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Reserve < 0\n\t\t\t\t\t\tif minpttl < 0 {\n\t\t\t\t\t\t\treturn nil, fmt.Errorf(\"cache min TTL can not be negative: %d\", minpttl)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tca.minpttl = time.Duration(minpttl) * time.Second\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tcase Denial:\n\t\t\t\targs := c.RemainingArgs()\n\t\t\t\tif len(args) == 0 {\n\t\t\t\t\treturn nil, c.ArgErr()\n\t\t\t\t}\n\t\t\t\tncap, err := strconv.Atoi(args[0])\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\t\t\t\tca.ncap = ncap\n\t\t\t\tif len(args) > 1 {\n\t\t\t\t\tnttl, err := strconv.Atoi(args[1])\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, err","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/coredns/coredns/blob/558c9757a92b361e550bdba82d0b4ddf3d12d595/plugin/cache/setup.go#L82-L118","documentation":"When the cache plugin's directive specifies a minimum positive-response TTL (`cache <zones> <pttl> <minpttl>`), the min TTL must not be negative. Unlike the main TTL, zero IS allowed for the min TTL (meaning no floor); only negative values trigger this error in cacheParse.","triggerScenarios":"Corefile like `cache example.org 30 -5` where args[2] of the success clause parses to a negative integer and is assigned to ca.minpttl.","commonSituations":"Sign typos in generated configs, misplacing a hyphen from another directive, or misunderstanding that min TTL floor must be 0 or positive.","solutions":["Change the min positive TTL to 0 or a positive integer, e.g. `cache example.org 30 5`.","Drop the third argument if no floor is needed; the min TTL then defaults to 0.","Check whether minpttl <= pttl constraints make sense for your intent (min TTL should typically be <= the max TTL)."],"exampleFix":"// before (Corefile)\ncache example.org 30 -5\n\n// after\ncache example.org 30 5","handlingStrategy":"validation","validationCode":"const minPttl = 5; if (!Number.isInteger(minPttl) || minPttl < 0) { throw new Error(`cache min success TTL must be >= 0, got ${minPttl}`); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember min TTL of 0 is allowed; only negatives are invalid.","Keep min TTL <= max TTL for coherent behavior.","Watch for stray '-' characters in generated configs."],"tags":["coredns","cache","config","ttl","min-ttl"],"backgroundTag":"invalid-config-value","analyzedSha":"558c9757a92b361e550bdba82d0b4ddf3d12d595","analyzedAt":"2026-09-06T22:47:02.106Z","contentChangedAt":"2026-09-06T22:47:02.106Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}