caddyserver/caddy · warning
humanize: size cannot be parsed: %s
Error message
humanize: size cannot be parsed: %s
What it means
Returned by the templates module's humanize function, format 'size', when the argument cannot be parsed as an unsigned 64-bit integer (strconv.ParseUint fails). The value is then passed to humanize.Bytes to render like '1.5 MB'.
Source
Thrown at modules/caddyhttp/templates/tplcontext.go:484
// funcHumanize transforms size and time inputs to a human readable format.
//
// Size inputs are expected to be integers, and are formatted as a
// byte size, such as "83 MB".
//
// Time inputs are parsed using the given layout (default layout is RFC1123Z)
// and are formatted as a relative time, such as "2 weeks ago".
// See https://pkg.go.dev/time#pkg-constants for time layout docs.
func (c TemplateContext) funcHumanize(formatType, data string) (string, error) {
// The format type can optionally be followed
// by a colon to provide arguments for the format
parts := strings.Split(formatType, ":")
switch parts[0] {
case "size":
dataint, dataerr := strconv.ParseUint(data, 10, 64)
if dataerr != nil {
return "", fmt.Errorf("humanize: size cannot be parsed: %s", dataerr.Error())
}
return humanize.Bytes(dataint), nil
case "time":
timelayout := time.RFC1123Z
if len(parts) > 1 {
timelayout = parts[1]
}
dataint, dataerr := time.Parse(timelayout, data)
if dataerr != nil {
return "", fmt.Errorf("humanize: time cannot be parsed: %s", dataerr.Error())
}
return humanize.Time(dataint), nil
}
return "", fmt.Errorf("no know function was given")
}View on GitHub (pinned to 50e54ee279)
Solutions
- Pass a raw non-negative integer byte count: {{ humanize "size" "1500000" }}
- Pipe through placeholders that yield integers, e.g. {{ humanize "size" (printf "%d" .Size) }}
- Default empty values first: {{ default "0" .Size }} before humanizing
- Pre-format floats to integers in the template (printf '%.0f')
Example fix
<!-- before -->
{{ humanize "size" "12.5" }}
<!-- after -->
{{ humanize "size" "13" }} Defensive patterns
Strategy: validation
Validate before calling
{{ $size := default "0" .Size }}{{ $size := printf "%.0f" (parseFloat $size) }}{{ humanize "size" $size }} Type guard
{{ if and (ne .Size "") (not (strings.Contains .Size ".")) (not (strings.HasPrefix .Size "-")) }}{{ humanize "size" .Size }}{{ end }} Prevention
- Normalize sizes to non-negative integers before humanize
- Default empty placeholders to 0 upstream of the template
- Unit-test templates with edge-case sizes (empty, float, negative)
When it happens
Trigger: {{ humanize "size" "12.5" }} (float), {{ humanize "size" "-1" }} (negative), {{ humanize "size" "1_000" }} or any non-numeric string such as an empty placeholder result.
Common situations: Feeding a float-formatted size from a template variable, a placeholder that resolves to empty when a header is missing, or sizes copied from human-readable strings ('10KB') instead of raw byte counts.
Related errors
- humanize: time cannot be parsed: %s
- no know function was given
- parsing environment file: %v
- can't parse line %d; line should be in KEY=VALUE format
- missing or empty key on line %d
AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15).
Data as JSON: /api/errors/d6f9b9f763e5bc77.
Report an issue: GitHub.