{"record":{"id":"eb3824f4e7cca48a","repo":"docker/cli","slug":"value-is-too-precise","errorCode":null,"errorMessage":"value is too precise","messagePattern":"value is too precise","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/opts.go","lineNumber":366,"sourceCode":"// Type returns the type\nfunc (*NanoCPUs) Type() string {\n\treturn \"decimal\"\n}\n\n// Value returns the value in int64\nfunc (c *NanoCPUs) Value() int64 {\n\treturn int64(*c)\n}\n\n// ParseCPUs takes a string ratio and returns an integer value of nano cpus\nfunc ParseCPUs(value string) (int64, error) {\n\tcpu, ok := new(big.Rat).SetString(value)\n\tif !ok {\n\t\treturn 0, fmt.Errorf(\"failed to parse %v as a rational number\", value)\n\t}\n\tnano := cpu.Mul(cpu, big.NewRat(1e9, 1))\n\tif !nano.IsInt() {\n\t\treturn 0, errors.New(\"value is too precise\")\n\t}\n\treturn nano.Num().Int64(), nil\n}\n\n// ParseLink parses and validates the specified string as a link format (name:alias)\nfunc ParseLink(val string) (string, string, error) {\n\tif val == \"\" {\n\t\treturn \"\", \"\", errors.New(\"empty string specified for links\")\n\t}\n\t// We expect two parts, but restrict to three to allow detecting invalid formats.\n\tarr := strings.SplitN(val, \":\", 3)\n\n\t// TODO(thaJeztah): clean up this logic!!\n\tif len(arr) > 2 {\n\t\treturn \"\", \"\", errors.New(\"bad format for links: \" + val)\n\t}\n\t// TODO(thaJeztah): this should trim the \"/\" prefix as well??\n\tif len(arr) == 1 {","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/opts.go#L348-L384","documentation":"Returned by ParseCPUs (opts/opts.go:366) when a CPU ratio string, after being parsed as a big.Rat and multiplied by 1e9 (to convert to nano-CPUs), does not produce a whole integer. This means the requested precision exceeds nanosecond granularity — the value has more significant decimal places than 9, or is a fraction that doesn't divide evenly into whole nanos.","triggerScenarios":"ParseCPUs (used by the --cpus flag via NanoCPUs.Set) receives a value with more than 9 decimal places of CPU precision, or a rational fraction whose product with 1e9 is non-integer. For example: '--cpus 0.1234567891' (10 decimal places) or '--cpus 1/7'. The big.Rat multiplication by 1e9 yields a non-integer result, so nano.IsInt() returns false.","commonSituations":"Over-precise CPU specification, programmatic generation of CPU values with excessive decimal places, or passing a rational fraction like '1/3' that doesn't map to whole nanoseconds.","solutions":["Round the CPU value to at most 3 decimal places (1ms precision): '--cpus 0.5', '--cpus 1.25', '--cpus 0.001'.","Avoid fractional denominators that don't divide 1e9 evenly; use decimal notation instead of rational fractions.","If computing CPU from a formula, round the result before passing to --cpus."],"exampleFix":"// before: too many decimal places\n// docker run --cpus=0.1234567891 nginx\n\n// after: round to 3 decimal places\n// docker run --cpus=0.123 nginx","handlingStrategy":"validation","validationCode":"func validateCPUPrecision(value string) error {\n    cpu, ok := new(big.Rat).SetString(value)\n    if !ok {\n        return fmt.Errorf(\"failed to parse %s as a rational number\", value)\n    }\n    nano := cpu.Mul(cpu, big.NewRat(1e9, 1))\n    if !nano.IsInt() {\n        return fmt.Errorf(\"CPU value %s is too precise; round to at most 3 decimal places (e.g., 0.5, 1.25)\", value)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if _, err := opts.ParseCPUs(value); err != nil {\n    if err.Error() == \"value is too precise\" {\n        return fmt.Errorf(\"CPU value %q exceeds nano-precision; round to <= 3 decimal places\", value)\n    }\n    return err\n}","preventionTips":["Round CPU values to at most 3 decimal places (e.g., 0.5, 1.25, 0.001).","Avoid rational fractions (like 1/3) that don't divide evenly into whole nanoseconds.","Validate computed CPU values with ParseCPUs before formatting into --cpus flags."],"tags":["cpu","validation","precision","cli-flag"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}