caddyserver/caddy · warning

humanize: time cannot be parsed: %s

Error message

humanize: time cannot be parsed: %s

What it means

Returned by the templates module's humanize function, format 'time', when time.Parse fails on the input using the given layout (default RFC1123Z, or the layout after the colon like 'time:2006-01-02'). The error string from time.Parse is embedded.

Source

Thrown at modules/caddyhttp/templates/tplcontext.go:496

	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")
}

// funcMaybe invokes the plugged-in function named functionName if it is plugged in
// (is a module in the 'http.handlers.templates.functions' namespace). If it is not
// available, a log message is emitted.
//
// The first argument is the function name, and the rest of the arguments are
// passed on to the actual function.
//
// This function is useful for executing templates that use components that may be
// considered as optional in some cases (like during local development) where you do
// not want to require everyone to have a custom Caddy build to be able to execute
// your template.

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Specify the matching Go layout: {{ humanize "time:2006-01-02" "2024-01-01" }}
  2. Or pass the time in RFC1123Z form ('Mon, 02 Jan 2006 15:04:05 -0700')
  3. Use Go's reference date (Jan 2 15:04:05 2006 MST) when writing the layout, never yyyy/dd style
  4. Default empty inputs to a known timestamp before humanizing

Example fix

<!-- before -->
{{ humanize "time" "2024-01-01" }}

<!-- after -->
{{ humanize "time:2006-01-02" "2024-01-01" }}
Defensive patterns

Strategy: validation

Validate before calling

{{ $t := "2024-01-01" }}{{ if not (time.Parse "2006-01-02" $t) }}bad{{ end }}{{ humanize "time:2006-01-02" $t }}

Prevention

When it happens

Trigger: {{ humanize "time" "2024-01-01" }} with the default RFC1123Z layout mismatch, or a custom layout that does not match the data, e.g. {{ humanize "time:2006-01-02" "Jan 1 2024" }}.

Common situations: Feeding ISO dates while forgetting the default is RFC1123Z, mixing up Go reference-time layouts (using yyyy-mm-dd instead of 2006-01-02), or an empty/placeholder-derived timestamp string.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/10249acf7d1642c9. Report an issue: GitHub.