{"record":{"id":"15781ae0506cca04","repo":"GoogleContainerTools/skaffold","slug":"listing-copied-files-w","errorCode":null,"errorMessage":"listing copied files: %w","messagePattern":"listing copied files: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/docker/parse.go","lineNumber":114,"sourceCode":"\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)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"listing copied files: %w\", err)\n\t}\n\n\treturn expandSrcGlobPatterns(workspace, cpCmds)\n}\n\nfunc ExtractOnlyCopyCommands(absDockerfilePath string) ([]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\tvar copied []FromTo\n\tworkdir := \"/\"","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/docker/parse.go#L96-L132","documentation":"extractCopyCommands walked the parsed (and OnBuild-expanded) instruction list to determine which files each COPY/ADD pulls in; when that fails — e.g. a stage referenced in COPY --from does not exist, or the instruction cannot be resolved against the build context — ReadCopyCmdsFromDockerfile wraps the failure with 'listing copied files'. Dependency computation aborts because the set of copied files cannot be determined.","triggerScenarios":"ReadCopyCmdsFromDockerfile invoked on a Dockerfile whose COPY --from=<stage> references a nonexistent stage, whose multi-stage FROM names are duplicated/invalid, or where an instruction needed for copy extraction is malformed after build-arg/ONBUILD expansion.","commonSituations":"Renaming a build stage but forgetting to update COPY --from references; ONBUILD parent images introducing COPY instructions that reference missing context; complex multi-stage files where a stage is referenced before it is defined.","solutions":["Ensure every COPY --from=<name> references a stage defined by an earlier FROM in the same Dockerfile","Give each stage an explicit unique 'FROM image AS name' and fix typos in stage names","Test with 'docker build .' — if docker itself rejects the stage reference, fix it the same way","If the error comes from an ONBUILD parent image, inspect that image's Dockerfile history (docker inspect) and adjust your context accordingly"],"exampleFix":"// before\nFROM golang AS build\nFROM alpine\nCOPY --from=buildr /app/bin /bin\n// after\nFROM golang AS build\nFROM alpine\nCOPY --from=build /app/bin /bin","handlingStrategy":"validation","validationCode":"func validateCopyFromStages(dockerfilePath string) error {\n    stages := map[string]bool{}\n    lines := readLines(dockerfilePath)\n    for _, l := range lines {\n        if m := fromStageRe.FindStringSubmatch(l); m != nil {\n            stages[strings.ToLower(m[1])] = true\n        }\n        if m := copyFromRe.FindStringSubmatch(l); m != nil && !stages[strings.ToLower(m[1])] {\n            return fmt.Errorf(\"COPY --from=%q references undefined stage\", m[1])\n        }\n    }\n    return nil\n}","typeGuard":"func stageDefined(dockerfileContent, stage string) bool {\n    re := regexp.MustCompile(`(?i)^FROM\\s+\\S+\\s+AS\\s+(\\S+)`)\n    for _, l := range strings.Split(dockerfileContent, \"\\n\") {\n        if m := re.FindStringSubmatch(l); m != nil && strings.EqualFold(m[1], stage) {\n            return true\n        }\n    }\n    return false\n}","tryCatchPattern":"fts, err := skaffold.ReadCopyCmdsFromDockerfile(path, args, cfg, false)\nif err != nil && strings.Contains(err.Error(), \"listing copied files\") {\n    return fmt.Errorf(\"check COPY --from stage names and FROM ordering: %w\", err)\n}","preventionTips":["Always name stages explicitly (FROM x AS name) and reference only defined names","Run 'docker build .' before Skaffold — it reports bad stage references too","Grep for 'COPY --from' after any stage rename to catch stale references","Inspect ONBUILD parent images (docker inspect) to know what instructions they inject"],"tags":["dockerfile","copy","multistage"],"backgroundTag":"dockerfile-copy-source-not-found","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"}