slimtoolkit/slim · error

got an invalid escape sequence: %s

Error message

got an invalid escape sequence: %s

What it means

While decoding the HEALTHCHECK retries value as a C-escape, the second character is looked up in a table of known escapes (\a \b \t \n \v \f \r). If the byte after the backslash is not one of these, the parser cannot map it to a numeric retries value and records this error on the returned err.

Source

Thrown at pkg/docker/dockerfile/reverse/reverse.go:849

			// retries are a unicode string
			retries, err = strconv.ParseInt(strings.TrimPrefix(paramParts[3], `\U`), 16, 64)
		} else if strings.Index(paramParts[3], `\`) == 0 {
			// retries is printed as a C-escape
			if len(paramParts[3]) != 2 {
				err = fmt.Errorf("expected retries (%s) to be an escape sequence", paramParts[3])
			} else {
				escapeCodes := map[byte]int64{
					byte('a'): 7,
					byte('b'): 8,
					byte('t'): 9,
					byte('n'): 10,
					byte('v'): 11,
					byte('f'): 12,
					byte('r'): 13,
				}
				var ok bool
				if retries, ok = escapeCodes[(paramParts[3])[1]]; !ok {
					err = fmt.Errorf("got an invalid escape sequence: %s", paramParts[3])
				}
			}
		} else if len(paramParts[3]) > 0 {
			retries = int64((paramParts[3])[0])
		}

		if err != nil {
			log.Errorf("[%s] config.Retries err = %v", paramParts[3], err)
		} else {
			config.Retries = int(retries)
		}

		var testType string
		if len(config.Test) > 0 {
			testType = config.Test[0]
		}

		switch testType {

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Replace the retries parameter with a supported escape (\a, \b, \t, \n, \v, \f, \r), a \Uxxxx unicode escape, or a plain numeric string.
  2. Remove the HEALTHCHECK metadata if the original escape is required and cannot be represented.
  3. Patch the ingestion to accept the escape by normalizing the history value before invoking the reverse builder.

Example fix

// before (unsupported escape)
HEALTHCHECK --retries=\\q ["CMD", "curl", "-f", "http://localhost/"]
// after (supported escape)
HEALTHCHECK --retries=\\n ["CMD", "curl", "-f", "http://localhost/"]
Defensive patterns

Strategy: validation

Validate before calling

var validEscapes = map[byte]bool{'a':true,'b':true,'t':true,'n':true,'v':true,'f':true,'r':true}
func validEscape(p string) bool {
	return !strings.HasPrefix(p, "\\") || strings.HasPrefix(p, "\\U") || (len(p) == 2 && validEscapes[p[1]])
}

Try / catch

if err := buildErr; err != nil && strings.Contains(err.Error(), "invalid escape sequence") {
	// normalize retries to numeric form and retry the build
}

Prevention

When it happens

Trigger: A HEALTHCHECK 4th parameter of exactly 2 characters starting with a backslash whose second character is not a recognized escape letter, e.g. \\q, \\1, \\s, when calling the reverse Dockerfile builder (FailOn/Error/Run/NewBasicImageBuilder).

Common situations: History metadata containing octal/hex escapes (\\033, \\x07) that the parser does not support; typos in hand-written HEALTHCHECK strings; tooling that URL- or shell-escaped the retries value.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/765953be5a1cac85. Report an issue: GitHub.