caddyserver/caddy · error

heredoc marker on line #%d must contain only alphanumeric ch

Error message

heredoc marker on line #%d must contain only alphanumeric characters, dashes and underscores; got '%s'

What it means

The heredoc marker (text between << and end of the opening line) contains characters outside [A-Za-z0-9_-]. The lexer enforces this via heredocMarkerRegexp so the closing marker line is unambiguous.

Source

Thrown at caddyconfig/caddyfile/lexer.go:168

			}

			// after hitting a newline, we know that the heredoc marker
			// is the characters after the two << and the newline.
			// we reset the val because the heredoc is syntax we don't
			// want to keep.
			if ch == '\n' {
				if len(val) == 2 {
					return false, fmt.Errorf("missing opening heredoc marker on line #%d; must contain only alphanumeric characters, dashes and underscores; got empty string", l.line)
				}

				// check if there's too many <
				if string(val[:3]) == "<<<" {
					return false, fmt.Errorf("too many '<' for heredoc on line #%d; only use two, for example <<END", l.line)
				}

				heredocMarker = string(val[2:])
				if !heredocMarkerRegexp.Match([]byte(heredocMarker)) {
					return false, fmt.Errorf("heredoc marker on line #%d must contain only alphanumeric characters, dashes and underscores; got '%s'", l.line, heredocMarker)
				}

				inHeredoc = true
				l.skippedLines++
				val = nil
				continue
			}
			val = append(val, ch)
			continue
		}

		// if we're in a heredoc, all characters are read as-is
		if inHeredoc {
			val = append(val, ch)

			if ch == '\n' {
				l.skippedLines++
			}

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Rename the marker to only letters, digits, dashes, underscores (e.g. <<EOF or <<HTML_END)
  2. Use the same marker on the closing line
  3. Do not quote the marker

Example fix

# before
respond <<'EOF'
# after
respond <<EOF
Defensive patterns

Strategy: validation

Validate before calling

var markerRe = regexp.MustCompile(`^[A-Za-z0-9_-]+$`)
if !markerRe.MatchString(marker) {
    return fmt.Errorf("bad heredoc marker %q", marker)
}

Prevention

When it happens

Trigger: Opening a heredoc with a marker containing spaces, dots, quotes, or other symbols, e.g. <<E.OF or <<"EOF" (quoted markers as in bash are not supported).

Common situations: Porting bash heredoc syntax with quoted delimiters (<<'EOF'), or markers containing punctuation like '.' or '/'.

Related errors


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