{"record":{"id":"edd3f403f1ad6cfe","repo":"GoogleContainerTools/skaffold","slug":"finding-changed-file-s-relative-to-context-q-w","errorCode":null,"errorMessage":"finding changed file %s relative to context %q: %w","messagePattern":"finding changed file (.+?) relative to context %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/sync/sync.go","lineNumber":139,"sourceCode":"\t\t\tDelete:   toDelete,\n\t\t}, nil\n\t}\n\n\t// deleted files are no longer contained in the syncMap, so we need to rebuild\n\tif len(e.Deleted) > 0 {\n\t\treturn nil, nil\n\t}\n\n\tsyncMap, err := SyncMap(ctx, a, cfg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"inferring syncmap for image %q: %w\", a.ImageName, err)\n\t}\n\n\ttoCopy := make(map[string][]string)\n\tfor _, f := range append(e.Modified, e.Added...) {\n\t\trelPath, err := filepath.Rel(a.Workspace, f)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"finding changed file %s relative to context %q: %w\", f, a.Workspace, err)\n\t\t}\n\n\t\tmatches := false\n\t\tfor _, p := range a.Sync.Infer {\n\t\t\tmatches, err = doublestar.PathMatch(filepath.FromSlash(p), relPath)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"pattern error for %q: %w\", relPath, err)\n\t\t\t}\n\t\t\tif matches {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif !matches {\n\t\t\tlog.Entry(ctx).Infof(\"Changed file %s does not match any sync pattern. Skipping sync\", relPath)\n\t\t\treturn nil, nil\n\t\t}\n\n\t\tif dsts, ok := syncMap[relPath]; ok {","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/sync/sync.go#L121-L157","documentation":"Skaffold's inferred file sync (inferredSyncItem) computes each changed/added file's path relative to the artifact's workspace so it can match it against the `sync.infer` patterns. When filepath.Rel(workspace, file) fails, the file cannot be expressed relative to the build context, and Skaffold wraps and returns the underlying error with this message.","triggerScenarios":"A file event arrives whose absolute path is not underneath a.Workspace (e.g. event paths with different volume spellings, symlinked workspaces, or a workspace configured as a relative/nonexistent path), making filepath.Rel return an error.","commonSituations":"Watching files via a symlinked directory while skaffold.yaml names the real path; running on a case-insensitive filesystem where casing differs between config and events; Docker/K8s file-watch events referencing temp files outside the workspace.","solutions":["Verify the artifact's `workspace:` in skaffold.yaml is the absolute real path (resolve symlinks) containing the watched files","Ensure the file watcher is started with the same absolute path passed as the artifact workspace","Fix path casing/slash normalization (use filepath.FromSlash/Clean consistently) before calling NewItem"],"exampleFix":"// before\nworkspace: ./service   # relative, may resolve differently from watcher\n// after\nworkspace: /home/dev/project/service  # absolute, symlink-resolved","handlingStrategy":"validation","validationCode":"ws, err := filepath.EvalSymlinks(a.Workspace)\nif err != nil { return err }\nfor _, f := range append(e.Modified, e.Added...) {\n    if _, err := filepath.Rel(ws, f); err != nil {\n        return fmt.Errorf(\"file %s not under workspace %s\", f, ws)\n    }\n}","typeGuard":"func fileInWorkspace(ws, f string) bool {\n    rel, err := filepath.Rel(ws, f)\n    return err == nil && rel != \"..\" && !strings.HasPrefix(rel, \"..\"+string(filepath.Separator))\n}","tryCatchPattern":"item, err := sync.NewItem(ctx, a, tag, e, cfg, builds)\nif err != nil {\n    if strings.Contains(err.Error(), \"relative to context\") {\n        log.Warnf(\"skipping sync for out-of-workspace file: %v\", err)\n        return nil\n    }\n    return err\n}","preventionTips":["Use absolute, symlink-resolved workspace paths in skaffold.yaml","Ensure the file watcher watches the same absolute path as the artifact workspace","Normalize paths with filepath.Clean/EvalSymlinks before sync"],"tags":["skaffold","sync","filepath","file-watch"],"backgroundTag":"filepath-rel-failure","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"}