{"record":{"id":"801e8ee125206241","repo":"hashicorp/nomad","slug":"could-not-parse-value-as-bytes-v","errorCode":null,"errorMessage":"could not parse value as bytes: %v","messagePattern":"could not parse value as bytes: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/quota_apply.go","lineNumber":365,"sourceCode":"\t\treturn nil, fmt.Errorf(\"invalid variables limit: %v\", err)\n\t}\n\thostVolumesLimit, err := parseQuotaMegabytes(m[\"host_volumes\"])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid host_volumes limit: %v\", err)\n\t}\n\n\treturn &api.QuotaStorageResources{\n\t\tVariablesMB:   variablesLimit,\n\t\tHostVolumesMB: hostVolumesLimit,\n\t}, nil\n}\n\nfunc parseQuotaMegabytes(raw any) (int, error) {\n\tswitch val := raw.(type) {\n\tcase string:\n\t\tb, err := humanize.ParseBytes(val)\n\t\tif err != nil {\n\t\t\treturn 0, fmt.Errorf(\"could not parse value as bytes: %v\", err)\n\t\t}\n\t\treturn int(b >> 20), nil\n\tcase int:\n\t\treturn val, nil\n\tcase nil:\n\t\treturn 0, nil\n\tdefault:\n\t\treturn 0, fmt.Errorf(\"invalid type %T\", raw)\n\t}\n}\n\nfunc parseDeviceResource(result *[]*api.RequestedDevice, list *ast.ObjectList) error {\n\tfor idx, o := range list.Items {\n\t\tif l := len(o.Keys); l == 0 {\n\t\t\treturn multierror.Prefix(fmt.Errorf(\"missing device name\"), fmt.Sprintf(\"resources, device[%d]->\", idx))\n\t\t} else if l > 1 {\n\t\t\treturn multierror.Prefix(fmt.Errorf(\"only one name may be specified\"), fmt.Sprintf(\"resources, device[%d]->\", idx))\n\t\t}","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/quota_apply.go#L347-L383","documentation":"parseQuotaMegabytes converts a quota value into megabytes. For string values it delegates to hashicorp/go-humanize's ParseBytes; if the string is not a recognizable byte quantity (number + optional unit), it returns \"could not parse value as bytes\" wrapping the underlying error. Quota files must express sizes either as human-readable byte strings or plain integer megabytes.","triggerScenarios":"A quota spec's size field (memory, variables, host_volumes) is a string like \"5 giga\", \"100\", \"MB\", \"1,000MB\", or contains a trailing space/currency symbol that ParseBytes rejects. Note bare numeric strings like \"100\" actually parse as bytes, often surprising users who meant megabytes.","commonSituations":"Typos in units, comma thousands separators (\"1,024MB\"), locale-decimal values (\"1,5GB\"), or quoting an integer when the file format expects an int and vice versa.","solutions":["Rewrite the value using units go-humanize understands: \"500MB\", \"1GiB\", \"2GB\", or \"1024KB\".","Remove commas and stray whitespace: use \"1024MB\" not \"1,024 MB\".","Inspect the wrapped error message for the exact position/character that failed parsing.","Switch to an unquoted integer if you want to specify the limit directly in megabytes."],"exampleFix":"// before\nmemory = \"1,024 MB\"\n// after\nmemory = \"1024MB\"","handlingStrategy":"validation","validationCode":"if s, ok := raw.(string); ok {\n    if _, err := humanize.ParseBytes(s); err != nil {\n        return fmt.Errorf(\"quota size %q is not parseable as bytes: %w\", s, err)\n    }\n}","typeGuard":"func parseableBytes(v any) bool {\n    s, ok := v.(string)\n    if !ok {\n        return true // ints and nil are accepted directly\n    }\n    _, err := humanize.ParseBytes(s)\n    return err == nil\n}","tryCatchPattern":null,"preventionTips":["Never use commas, currency symbols, or rates (\"MB/s\") in size strings","Remember bare numeric strings like \"100\" are treated as 100 bytes, not MB — prefer explicit units","Test quota files with go-humanize ParseBytes locally before applying","Prefer unquoted integers (megabytes) for machine-generated specs"],"tags":["nomad","parsing","bytes","go-humanize"],"backgroundTag":"invalid-byte-size-format","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}