{"record":{"id":"bea5944497d569e8","repo":"coredns/coredns","slug":"prefetch-amount-should-be-positive-d","errorCode":null,"errorMessage":"prefetch amount should be positive: %d","messagePattern":"prefetch amount should be positive: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/cache/setup.go","lineNumber":147,"sourceCode":"\t\t\t\t\t\t}\n\t\t\t\t\t\t// Reserve < 0\n\t\t\t\t\t\tif minnttl < 0 {\n\t\t\t\t\t\t\treturn nil, fmt.Errorf(\"cache min TTL can not be negative: %d\", minnttl)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tca.minnttl = time.Duration(minnttl) * time.Second\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tcase \"prefetch\":\n\t\t\t\targs := c.RemainingArgs()\n\t\t\t\tif len(args) == 0 || len(args) > 3 {\n\t\t\t\t\treturn nil, c.ArgErr()\n\t\t\t\t}\n\t\t\t\tamount, 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\tif amount < 0 {\n\t\t\t\t\treturn nil, fmt.Errorf(\"prefetch amount should be positive: %d\", amount)\n\t\t\t\t}\n\t\t\t\tca.prefetch = amount\n\n\t\t\t\tif len(args) > 1 {\n\t\t\t\t\tdur, err := time.ParseDuration(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\tca.duration = dur\n\t\t\t\t}\n\t\t\t\tif len(args) > 2 {\n\t\t\t\t\tpct := args[2]\n\t\t\t\t\tif x := pct[len(pct)-1]; x != '%' {\n\t\t\t\t\t\treturn nil, fmt.Errorf(\"last character of percentage should be `%%`, but is: %q\", x)\n\t\t\t\t\t}\n\t\t\t\t\tpct = pct[:len(pct)-1]\n\n\t\t\t\t\tnum, err := strconv.Atoi(pct)","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/coredns/coredns/blob/558c9757a92b361e550bdba82d0b4ddf3d12d595/plugin/cache/setup.go#L129-L165","documentation":"The cache plugin's `prefetch amount [duration [percentage]]` option requires the prefetch amount to be positive (or zero, which the check `amount < 0` permits — negative amounts are rejected). cacheParse returns this error at setup when the first prefetch argument is a negative integer.","triggerScenarios":"Corefile line like `prefetch -1` or `prefetch -10 1m` inside a cache block where strconv.Atoi(args[0]) yields a negative number.","commonSituations":"Sign typos, templated configs where a variable meant to be a count expands negative, or misunderstanding the option semantics (0 means disabled-ish, negative is invalid).","solutions":["Set the prefetch amount to a positive integer, e.g. `prefetch 1` or `prefetch 10 1m 10%`.","Remove the prefetch line if you do not want prefetching.","Check template variables that supply the amount.","Note amount 0 passes validation but effectively makes prefetch useless; prefer removing the option."],"exampleFix":"// before (Corefile)\ncache 30\n    prefetch -1\n\n// after\ncache 30\n    prefetch 1","handlingStrategy":"validation","validationCode":"const amount = 1; if (!Number.isInteger(amount) || amount < 0) { throw new Error(`prefetch amount must be a non-negative integer, got ${amount}`); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a positive integer (commonly 1-10) for prefetch amount.","Remove the prefetch option entirely when prefetching is not wanted.","Sanitize template variables feeding the amount."],"tags":["coredns","cache","prefetch","config","validation"],"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-14T00:17:10.932Z"}