{"record":{"id":"3938d17527c8aab5","repo":"GoogleContainerTools/skaffold","slug":"parsing-dockerfile-q-w","errorCode":null,"errorMessage":"parsing dockerfile %q: %w","messagePattern":"parsing dockerfile %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/docker/parse.go","lineNumber":94,"sourceCode":"\tendLine int\n}\n\nvar (\n\t// RetrieveImage is overridden for unit testing\n\tRetrieveImage = retrieveImage\n)\n\n// ReadCopyCmdsFromDockerfile parses a given dockerfile for COPY commands accounting for build args, env vars, globs, etc\n// and returns an array of FromTos specifying the files that will be copied 'from' local dirs 'to' container dirs in the COPY statements\nfunc ReadCopyCmdsFromDockerfile(ctx context.Context, onlyLastImage bool, absDockerfilePath, workspace string, buildArgs map[string]*string, cfg Config) ([]FromTo, error) {\n\tr, err := os.ReadFile(absDockerfilePath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tres, err := parser.Parse(bytes.NewReader(r))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parsing dockerfile %q: %w\", absDockerfilePath, err)\n\t}\n\n\tif err := validateParsedDockerfile(bytes.NewReader(r), res); err != nil {\n\t\treturn nil, fmt.Errorf(\"parsing dockerfile %q: %w\", absDockerfilePath, err)\n\t}\n\n\tdockerfileLines := res.AST.Children\n\n\tif err := expandBuildArgs(dockerfileLines, buildArgs); err != nil {\n\t\treturn nil, fmt.Errorf(\"putting build arguments: %w\", err)\n\t}\n\n\tdockerfileLinesWithOnbuild, err := expandOnbuildInstructions(ctx, dockerfileLines, cfg)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tcpCmds, err := extractCopyCommands(ctx, dockerfileLinesWithOnbuild, onlyLastImage, cfg)","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/docker/parse.go#L76-L112","documentation":"ReadCopyCmdsFromDockerfile wraps any error returned by the BuildKit dockerfile parser (parser.Parse) with the absolute path of the Dockerfile it tried to parse. It means the Dockerfile text is syntactically invalid per the Dockerfile grammar, so Skaffold cannot extract COPY commands to compute build dependencies. The wrapped inner error from moby/buildkit names the line and specific syntax problem.","triggerScenarios":"Calling any Skaffold API that reaches ReadCopyCmdsFromDockerfile (artifact dependency computation via getDependencies, getDependenciesByDockerCopyFromTo, SyncMap) when the Dockerfile at absDockerfilePath fails parser.Parse — e.g. malformed instructions, unterminated quotes, bad escape directive, invalid heredoc syntax.","commonSituations":"Hand-edited Dockerfiles with typos (missing FROM line, broken continuation characters); Dockerfiles written for newer syntax (heredocs, --mount flags) parsed with an older parser; CRLF or encoding corruption; an editor or template engine emitting invalid intermediate Dockerfile content.","solutions":["Run 'docker build --check .' or hadolint on the Dockerfile to see the exact line and fix the syntax error","Verify the file at the path in the error message is the intended Dockerfile and is not truncated or corrupted","Check for syntax requiring a newer parser (heredocs, # syntax= directive) and add the correct '# syntax=' header or simplify the instruction","Regenerate the Dockerfile if it is produced by templating — the template output, not the template, is invalid"],"exampleFix":"// before\nRUN echo \"unterminated\n\n// after\nRUN echo \"terminated properly\"","handlingStrategy":"try-catch","validationCode":"func validateDockerfileSyntax(path string) error {\n    f, err := os.Open(path)\n    if err != nil { return err }\n    defer f.Close()\n    if _, err := parser.Parse(f); err != nil {\n        return fmt.Errorf(\"invalid Dockerfile %s: %w\", path, err)\n    }\n    return nil\n}\n// call before invoking skaffold; also lint in CI: hadolint Dockerfile","typeGuard":"func isParseableDockerfile(path string) bool {\n    f, err := os.Open(path)\n    if err != nil { return false }\n    defer f.Close()\n    _, perr := parser.Parse(f)\n    return perr == nil\n}","tryCatchPattern":"deps, err := skaffold.ReadCopyCmdsFromDockerfile(absPath, buildArgs, cfg, false)\nif err != nil {\n    var syntaxErr *os.PathError\n    if errors.As(err, &syntaxErr) {\n        return fmt.Errorf(\"check dockerfile path: %w\", err)\n    }\n    return fmt.Errorf(\"dockerfile syntax invalid; run 'docker build --check': %w\", err)\n}","preventionTips":["Lint every Dockerfile with hadolint or 'docker build --check' in CI before Skaffold runs","Pin the '# syntax=' directive when using BuildKit-only features","Keep Dockerfiles ASCII/LF; avoid editors that inject odd whitespace","Never let template engines emit Dockerfiles unchecked — validate the rendered output"],"tags":["dockerfile","parsing","syntax"],"backgroundTag":"dockerfile-parse-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}