{"record":{"id":"5739ca55c02b128e","repo":"docker/cli","slug":"invalid-restart-policy-format-maximum-retry-count","errorCode":null,"errorMessage":"invalid restart policy format: maximum retry count must be an integer","messagePattern":"invalid restart policy format: maximum retry count must be an integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/parse.go","lineNumber":96,"sourceCode":"// retry count, if set, must be an integer (negative values are allowed here\n// but may be rejected by the daemon).\nfunc ParseRestartPolicy(policy string) (container.RestartPolicy, error) {\n\tif policy == \"\" {\n\t\t// For backward compatibility, do not set an explicit default (\"no\"),\n\t\t// as older daemons may not support it.\n\t\treturn container.RestartPolicy{}, nil\n\t}\n\n\tname, count, ok := strings.Cut(policy, \":\")\n\tif ok && name == \"\" {\n\t\treturn container.RestartPolicy{}, errors.New(\"invalid restart policy format: no policy provided before colon\")\n\t}\n\n\tvar retryCount int\n\tif count != \"\" {\n\t\tc, err := strconv.Atoi(count)\n\t\tif err != nil {\n\t\t\treturn container.RestartPolicy{}, errors.New(\"invalid restart policy format: maximum retry count must be an integer\")\n\t\t}\n\t\tretryCount = c\n\t}\n\n\treturn container.RestartPolicy{\n\t\tName:              container.RestartPolicyMode(name),\n\t\tMaximumRetryCount: retryCount,\n\t}, nil\n}\n","sourceCodeStart":78,"sourceCodeEnd":106,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/parse.go#L78-L106","documentation":"Thrown by opts.ParseRestartPolicy when a retry count is present after the colon but strconv.Atoi fails to parse it as an integer. Only on-failure style policies use a retry count, and it must be a base-10 integer (negative values pass here but may be daemon-rejected).","triggerScenarios":"Calling opts.ParseRestartPolicy(\"on-failure:abc\"), or --restart=on-failure:5x, or a retry value with spaces or units.","commonSituations":"Typing the retry count as a float (\"on-failure:5.0\"), appending units/letters, or interpolating a non-numeric variable into the count position.","solutions":["Use a plain integer for the retry count, e.g. on-failure:5.","If the count comes from a variable, validate it is numeric before composing the string.","Drop the retry count if you only want the on-failure policy with daemon defaults."],"exampleFix":"// before\n_, _ = opts.ParseRestartPolicy(\"on-failure:abc\")\n// after\n_, _ = opts.ParseRestartPolicy(\"on-failure:5\")","handlingStrategy":"validation","validationCode":"_, count, ok := strings.Cut(policy, \":\")\nif ok && count != \"\" {\n    if _, err := strconv.Atoi(count); err != nil {\n        return fmt.Errorf(\"retry count %q must be an integer\", count)\n    }\n}\nrp, err := opts.ParseRestartPolicy(policy)","typeGuard":null,"tryCatchPattern":"rp, err := opts.ParseRestartPolicy(policy)\nif err != nil {\n    return err\n}","preventionTips":["Use strconv.Atoi on the count before composing the string.","Avoid floats or units in the retry count."],"tags":["restart-policy","validation","opts"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}