{"record":{"id":"4b8cc94d538ff61c","repo":"docker/cli","slug":"negative-timeout-d-is-invalid","errorCode":null,"errorMessage":"negative timeout %d is invalid","messagePattern":"negative timeout (.+?) is invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/plugin/enable.go","lineNumber":39,"sourceCode":"\t\t\tname := args[0]\n\t\t\tif err := runEnable(cmd.Context(), dockerCLI, name, opts); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\t_, _ = fmt.Fprintln(dockerCLI.Out(), name)\n\t\t\treturn nil\n\t\t},\n\t\tValidArgsFunction:     completeNames(dockerCLI, stateDisabled),\n\t\tDisableFlagsInUseLine: true,\n\t}\n\n\tflags := cmd.Flags()\n\tflags.IntVar(&opts.Timeout, \"timeout\", 30, \"HTTP client timeout (in seconds)\")\n\treturn cmd\n}\n\nfunc runEnable(ctx context.Context, dockerCli command.Cli, name string, opts client.PluginEnableOptions) error {\n\tif opts.Timeout < 0 {\n\t\treturn fmt.Errorf(\"negative timeout %d is invalid\", opts.Timeout)\n\t}\n\t_, err := dockerCli.Client().PluginEnable(ctx, name, opts)\n\treturn err\n}\n","sourceCodeStart":21,"sourceCodeEnd":44,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/plugin/enable.go#L21-L44","documentation":"Returned by runEnable (plugin/enable.go:39) when the --timeout flag is a negative integer. The timeout governs the HTTP client timeout passed to PluginEnable, so a negative value is meaningless and is rejected before any API call. The guard is a simple `opts.Timeout < 0` check.","triggerScenarios":"Running `docker plugin enable --timeout -1 PLUGIN` (or any negative value), typically from a script computing the timeout arithmetically and underflowing to a negative number.","commonSituations":"Shell arithmetic that subtracts more than intended, a misconfigured environment variable parsed as a negative int, or passing 0 thinking it means 'no timeout' then negating it.","solutions":["Use a non-negative timeout (0 is accepted and means use the default/no explicit limit).","Clamp computed timeout values with something like `max(0, computed)`.","Omit --timeout to keep the default of 30 seconds."],"exampleFix":"// before\ndocker plugin enable --timeout $((START-END)) PLUGIN   # may be negative\n// after\nt=$(( START - END )); [ \"$t\" -lt 0 ] && t=0; docker plugin enable --timeout \"$t\" PLUGIN","handlingStrategy":"validation","validationCode":"// Clamp the timeout before calling enable.\nfunc sanitizeTimeout(t int) int {\n    if t < 0 { return 0 }\n    return t\n}","typeGuard":"// isNonNegTimeout narrows ints that are valid enable timeouts.\nfunc isNonNegTimeout(t int) bool { return t >= 0 }","tryCatchPattern":null,"preventionTips":["Clamp arithmetic results with max(0, value).","Use 0 or omit --timeout when you want the default.","Validate env-var-sourced timeouts before passing them through."],"tags":["plugin","timeout","validation","docker-cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}