{"record":{"id":"71ad31599a5df2ad","repo":"slimtoolkit/slim","slug":"malformed-healthcheck-parameters-q","errorCode":null,"errorMessage":"malformed HEALTHCHECK parameters: %q","messagePattern":"malformed HEALTHCHECK parameters: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/docker/dockerfile/reverse/reverse.go","lineNumber":804,"sourceCode":"\t\t}\n\t\t// Cleans HEALTHCHECK part and splits the first part further\n\t\tparts := strings.SplitN(instParts[0], \" \", 2)\n\t\t// joins the first part of the string\n\t\tinstPart1 := strings.Join(parts[1:], \" \")\n\t\t// removes quotes from the first part of the string\n\t\tinstPart1 = strings.ReplaceAll(instPart1, \"\\\"\", \"\")\n\n\t\t// cleans it to assign it to the pointer config.Test\n\t\tconfig.Test = strings.Split(instPart1, \" \")\n\n\t\t// removes the } from the second part of the string\n\t\tinstPart2 := strings.Replace(instParts[1], \"}\", \"\", -1)\n\t\t// removes extra spaces from string\n\t\tinstPart2 = strings.TrimSpace(instPart2)\n\n\t\tparamParts := strings.SplitN(instPart2, \" \", 4)\n\t\tif len(paramParts) < 4 {\n\t\t\treturn strTest, &config, fmt.Errorf(\"malformed HEALTHCHECK parameters: %q\", data)\n\t\t}\n\t\tfor i, param := range paramParts {\n\t\t\tparamParts[i] = strings.Trim(param, \"\\\"'\")\n\t\t}\n\n\t\tvar err error\n\t\tconfig.Interval, err = time.ParseDuration(paramParts[0])\n\t\tif err != nil {\n\t\t\tlog.Errorf(\"[%s] config.Interval err = %v\", paramParts[0], err)\n\t\t}\n\n\t\tconfig.Timeout, err = time.ParseDuration(paramParts[1])\n\t\tif err != nil {\n\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 {","sourceCodeStart":786,"sourceCodeEnd":822,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/docker/dockerfile/reverse/reverse.go#L786-L822","documentation":"Thrown by the Dockerfile reverse-engineering parser when reconstructing a HEALTHCHECK instruction: the instruction body could not be split into the 4 required parameters (start-interval/check timing fields of the healthcheck flags). The parser splits the remainder of the HEALTHCHECK line on spaces with SplitN(..., 4) and requires all 4 parts; anything fewer means the parameters are structurally malformed, so the builder aborts with the offending data quoted.","triggerScenarios":"Parsing a HEALTHCHECK instruction whose parameter section has fewer than 4 space-separated quoted parameters, e.g. `HEALTHCHECK CMD curl -f http://localhost/ || exit 1` without the surrounding JSON-array form (`HEALTHCHECK [\"CMD\", \"curl\", ...]`-style reconstruction) or with parameters collapsed onto fewer tokens, when calling the reverse Dockerfile builder (Run/NewBasicImageBuilder).","commonSituations":"Reconstructing Dockerfiles from OCI image history where the original HEALTHCHECK used shell form instead of exec/JSON form; hand-edited image history strings; images built by tooling that emitted non-standard HEALTHCHECK metadata.","solutions":["Inspect the quoted data in the error and rewrite the HEALTHCHECK entry in image history/config metadata to the 4-parameter quoted form the parser expects.","If the source image's HEALTHCHECK is shell-form, drop the HEALTHCHECK metadata or convert it to JSON/exec form before running the reverse builder.","If the image is trusted and you only need the rest of the Dockerfile, pre-process the history to remove the malformed HEALTHCHECK instruction."],"exampleFix":"// before (shell form in history)\nHEALTHCHECK CMD curl -f http://localhost/ || exit 1\n// after (exec/JSON form with all parameters)\nHEALTHCHECK [\"CMD\", \"curl\", \"-f\", \"http://localhost/\"]","handlingStrategy":"validation","validationCode":"// validate HEALTHCHECK history entry before reverse-building\nfunc validHealthcheck(hist string) bool {\n\ti := strings.Index(hist, \"HEALTHCHECK\")\n\tif i < 0 { return true }\n\tparts := strings.SplitN(strings.TrimSpace(hist[i+len(\"HEALTHCHECK\"):]), \" \", 4)\n\treturn len(parts) == 4\n}","typeGuard":null,"tryCatchPattern":"if _, cfgErr := builder.Run(...); cfgErr != nil && strings.Contains(cfgErr.Error(), \"malformed HEALTHCHECK\") {\n\t// fall back: strip HEALTHCHECK from history and retry\n}","preventionTips":["Ensure image history HEALTHCHECK entries use the 4-parameter quoted/exec form","Never hand-edit image config history strings","Pre-scan image history for HEALTHCHECK instructions before reverse-engineering"],"tags":["dockerfile","healthcheck","parsing","docker"],"backgroundTag":"dockerfile-healthcheck-parse-failed","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}