hashicorp/nomad · error

could not parse value as bytes: %v

Error message

could not parse value as bytes: %v

What it means

parseCapacityBytes walks the filtered HCL node looking for a string literal, trims quotes, and passes it to humanize.ParseBytes. Any non-empty literal that humanize cannot parse as a byte quantity produces `could not parse value as bytes: <reason>`. This is the underlying error wrapped by the invalid capacity_min / capacity_max messages.

Source

Thrown at command/volume_register_csi.go:194

	}

	return vol, nil
}

func parseCapacityBytes(cap *ast.ObjectList) (int64, error) {
	if len(cap.Items) > 0 {
		for _, o := range cap.Elem().Items {
			lit, ok := o.Val.(*ast.LiteralType)
			if !ok {
				break
			}
			literal := strings.Trim(lit.Token.Text, "\"")
			if literal == "" {
				return 0, nil
			}
			b, err := humanize.ParseBytes(literal)
			if err != nil {
				return 0, fmt.Errorf("could not parse value as bytes: %v", err)
			}
			return int64(b), err
		}
	}
	return 0, nil
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Format the value with a humanize-compatible suffix: bytes, KB/MB/GB/TB (SI) or KiB/MiB/GiB/TiB (binary), e.g. "5GiB".
  2. Use a plain integer to express raw bytes.
  3. Use an empty string to represent zero/unset.

Example fix

// before
capacity_min = "1,5 GB"
// after
capacity_min = "1.5GB"
Defensive patterns

Strategy: validation

Validate before calling

func parseCapacity(s string) (int64, error) {
	if s == "" { return 0, nil }
	b, err := humanize.ParseBytes(strings.Trim(s, "\""))
	return int64(b), err
}
// call before constructing the spec
if _, err := parseCapacity(raw); err != nil { return err }

Try / catch

b, err := parseCapacityBytes(list.Filter("capacity_min"))
if err != nil {
	return fmt.Errorf("capacity must look like '10GiB' or '10000000000': %v", err)
}

Prevention

When it happens

Trigger: Any capacity value (capacity_min or capacity_max, also decodeHostVolume's capacity) that is a non-empty string not accepted by dustin/go-humanize.ParseBytes — e.g. "10 TBs", "1,5 GB", "bogus".

Common situations: Decimal commas instead of dots; invented units ("TBs", "gigs"); accidental whitespace/characters; forgetting that an empty string is the only 'unset' sentinel.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/a36cdedebbe19adf. Report an issue: GitHub.