{"record":{"id":"9fb5f39ede54777a","repo":"docker/cli","slug":"invalid-size-q","errorCode":null,"errorMessage":"invalid size: %q","messagePattern":"invalid size: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/opts.go","lineNumber":438,"sourceCode":"\tval, err := units.RAMInBytes(value)\n\t*m = MemBytes(val)\n\treturn err\n}\n\n// Type returns the type\nfunc (*MemBytes) Type() string {\n\treturn \"bytes\"\n}\n\n// Value returns the value in int64\nfunc (m *MemBytes) Value() int64 {\n\treturn int64(*m)\n}\n\n// UnmarshalJSON is the customized unmarshaler for MemBytes\nfunc (m *MemBytes) UnmarshalJSON(s []byte) error {\n\tif len(s) <= 2 || s[0] != '\"' || s[len(s)-1] != '\"' {\n\t\treturn fmt.Errorf(\"invalid size: %q\", s)\n\t}\n\tval, err := units.RAMInBytes(string(s[1 : len(s)-1]))\n\t*m = MemBytes(val)\n\treturn err\n}\n\n// MemSwapBytes is a type for human readable memory bytes (like 128M, 2g, etc).\n// It differs from MemBytes in that -1 is valid and the default.\ntype MemSwapBytes int64\n\n// Set sets the value of the MemSwapBytes by passing a string\nfunc (m *MemSwapBytes) Set(value string) error {\n\tif value == \"-1\" {\n\t\t*m = MemSwapBytes(-1)\n\t\treturn nil\n\t}\n\tval, err := units.RAMInBytes(value)\n\t*m = MemSwapBytes(val)","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/opts.go#L420-L456","documentation":"Thrown by MemBytes.UnmarshalJSON (opts.go:438) when the JSON token is not a properly quoted string. MemBytes memory sizes (e.g. for --memory in configs deserialized from JSON) must be a JSON string like \"512m\"; raw numbers, booleans, arrays, null, or unquoted tokens fail the length/quote check at line 437 before RAMInBytes is even attempted.","triggerScenarios":"JSON-unmarshaling into a MemBytes field with a numeric literal `512` instead of `\"512m\"`, an empty string `\"\"`, an unquoted value, or a non-string JSON type (number/bool/array/object). Line 437 requires len>2 and surrounding double quotes.","commonSituations":"Programmatic API clients sending memory as a JSON number rather than a units-string, configs authored with `\"memory\": 1073741824` instead of `\"memory\": \"1g\"`, or empty/default zero values serialized as empty strings.","solutions":["Encode the memory value as a JSON string with a units suffix: `\"memory\": \"512m\"`.","If you must use bytes, still quote it: `\"memory\": \"1073741824\"` (RAMInBytes accepts bare numbers).","Ensure the field is non-empty and at least 3 bytes including quotes (`\"0\"` is the minimum valid).","Switch the JSON encoder to emit strings for any MemBytes/MemSwapBytes field."],"exampleFix":"// before\n{ \"memory\": 536870912 }\n// after\n{ \"memory\": \"512m\" }","handlingStrategy":"validation","validationCode":"// Ensure JSON memory fields are quoted strings before unmarshaling into MemBytes.\nif len(raw) < 3 || raw[0] != '\"' || raw[len(raw)-1] != '\"' {\n    return fmt.Errorf(\"memory must be a JSON string like \\\"512m\\\", got %s\", raw)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Serialize memory as a JSON string with units (\"512m\", \"2g\").","Never send a raw JSON number for a MemBytes field.","Ensure the field is non-empty (\"0\" is the minimum valid quoted value).","Unit-test your API client's serialization of memory fields."],"tags":["docker","memory","json","validation","resource-limits","cli"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}