{"record":{"id":"c0bfe41846fc438e","repo":"slimtoolkit/slim","slug":"expected-retries-s-to-be-an-escape-sequence","errorCode":null,"errorMessage":"expected retries (%s) to be an escape sequence","messagePattern":"expected retries \\((.+?)\\) to be an escape sequence","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/docker/dockerfile/reverse/reverse.go","lineNumber":836,"sourceCode":"\t\t\tlog.Errorf(\"[%s] config.Timeout err = %v\", paramParts[1], err)\n\t\t}\n\n\t\tconfig.StartPeriod, err = time.ParseDuration(paramParts[2])\n\t\tif err != nil {\n\t\t\tlog.Errorf(\"[%s] config.StartPeriod err = %v\", paramParts[2], err)\n\t\t}\n\n\t\tvar retries int64\n\t\tif strings.Index(paramParts[3], `\\x`) != -1 {\n\t\t\t// retries are hex encoded\n\t\t\tretries, err = strconv.ParseInt(strings.TrimPrefix(paramParts[3], `\\x`), 16, 64)\n\t\t} else if strings.Index(paramParts[3], `\\U`) != -1 {\n\t\t\t// retries are a unicode string\n\t\t\tretries, err = strconv.ParseInt(strings.TrimPrefix(paramParts[3], `\\U`), 16, 64)\n\t\t} else if strings.Index(paramParts[3], `\\`) == 0 {\n\t\t\t// retries is printed as a C-escape\n\t\t\tif len(paramParts[3]) != 2 {\n\t\t\t\terr = fmt.Errorf(\"expected retries (%s) to be an escape sequence\", paramParts[3])\n\t\t\t} else {\n\t\t\t\tescapeCodes := map[byte]int64{\n\t\t\t\t\tbyte('a'): 7,\n\t\t\t\t\tbyte('b'): 8,\n\t\t\t\t\tbyte('t'): 9,\n\t\t\t\t\tbyte('n'): 10,\n\t\t\t\t\tbyte('v'): 11,\n\t\t\t\t\tbyte('f'): 12,\n\t\t\t\t\tbyte('r'): 13,\n\t\t\t\t}\n\t\t\t\tvar ok bool\n\t\t\t\tif retries, ok = escapeCodes[(paramParts[3])[1]]; !ok {\n\t\t\t\t\terr = fmt.Errorf(\"got an invalid escape sequence: %s\", paramParts[3])\n\t\t\t\t}\n\t\t\t}\n\t\t} else if len(paramParts[3]) > 0 {\n\t\t\tretries = int64((paramParts[3])[0])\n\t\t}","sourceCodeStart":818,"sourceCodeEnd":854,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/docker/dockerfile/reverse/reverse.go#L818-L854","documentation":"During HEALTHCHECK reverse parsing, the retries value (paramParts[3]) starts with a backslash, so the parser assumes it is an escape sequence (C-escape or unicode \\U form). An escape must be exactly 2 characters (e.g. \\n); a longer or shorter backslash-prefixed token cannot be decoded into the numeric retries value, so the builder records this error on the returned err.","triggerScenarios":"A HEALTHCHECK entry whose 4th parameter begins with a single backslash but is not exactly 2 characters long (e.g. \\\\n\\\\, or \\\\x1B, or a Windows-style path fragment) when running the reverse Dockerfile builder (FailOn/Error/Run/NewBasicImageBuilder).","commonSituations":"Images built on Windows or with shell-escaped retries values in history; history strings where backslashes were doubled or mangled by shell quoting; copy-pasted HEALTHCHECK metadata from docs.","solutions":["Fix the retries parameter in the image history/config so it is a single escape sequence like \\n, \\t, a \\Uxxxx unicode escape, or a plain numeric value.","Remove the HEALTHCHECK metadata from the image config if the retries value cannot be corrected.","Verify the history string was not backslash-escaped twice by the build tooling and re-ingest the image."],"exampleFix":"// before (malformed multi-char escape)\nHEALTHCHECK --retries=\\\\n\\\\ [\"CMD\", \"curl\", \"-f\", \"http://localhost/\"]\n// after (valid escape)\nHEALTHCHECK --retries=3 [\"CMD\", \"curl\", \"-f\", \"http://localhost/\"]","handlingStrategy":"validation","validationCode":"// retries must be a 2-char escape, \\Uxxxx, or plain value\nfunc validRetries(p string) bool {\n\tif !strings.HasPrefix(p, \"\\\\\") { return true }\n\tif strings.HasPrefix(p, \"\\\\U\") { return len(p) == 6 }\n\treturn len(p) == 2\n}","typeGuard":null,"tryCatchPattern":"if err := buildErr; err != nil && strings.Contains(err.Error(), \"expected retries\") {\n\t// sanitize or drop the HEALTHCHECK metadata, then rebuild\n}","preventionTips":["Keep --retries as a plain integer in image metadata","Avoid shell-escaping backslashes in HEALTHCHECK strings","Verify Windows-built images' history for doubled backslashes"],"tags":["dockerfile","healthcheck","escape-sequence","docker"],"backgroundTag":"invalid-escape-sequence","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}