{"record":{"id":"3878c27ce9bf6de5","repo":"GoogleContainerTools/skaffold","slug":"changed-file-s-can-t-be-found-relative-to-context","errorCode":null,"errorMessage":"changed file %s can't be found relative to context %q: %w","messagePattern":"changed file (.+?) can't be found relative to context %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/sync/sync.go","lineNumber":233,"sourceCode":"\t\treturn nil, fmt.Errorf(\"Sync: Auto is not supported by the build of %s\", a.ImageName)\n\t}\n}\n\nfunc latestTag(image string, builds []graph.Artifact) string {\n\tfor _, build := range builds {\n\t\tif build.ImageName == image {\n\t\t\treturn build.Tag\n\t\t}\n\t}\n\treturn \"\"\n}\n\nfunc intersect(ctx context.Context, contextWd, containerWd string, syncRules []*latest.SyncRule, files []string) (syncMap, error) {\n\tret := make(syncMap)\n\tfor _, f := range files {\n\t\trelPath, err := filepath.Rel(contextWd, f)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"changed file %s can't be found relative to context %q: %w\", f, contextWd, err)\n\t\t}\n\n\t\tdsts, err := matchSyncRules(syncRules, relPath, containerWd)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tif len(dsts) == 0 {\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\tret[f] = dsts\n\t}\n\treturn ret, nil\n}\n\nfunc matchSyncRules(syncRules []*latest.SyncRule, relPath, containerWd string) ([]string, error) {","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/sync/sync.go#L215-L251","documentation":"intersect maps each changed file into destination paths by first computing its path relative to the build context (contextWd). If filepath.Rel(contextWd, file) fails, the file cannot be related to the sync rules' source-relative paths, so Skaffold wraps the error.","triggerScenarios":"A file event path lies outside (or is differently rooted than) the artifact workspace passed as contextWd — e.g. jib/docker sync diff producing absolute container-style paths, symlinked or differently cased workspace roots.","commonSituations":"Jib incremental sync returning paths from the Jib build cache that don't share a prefix with the workspace; watcher started at repo root while artifact workspace is a subdirectory and events escape it; Windows drive-letter casing mismatch.","solutions":["Ensure the workspace in skaffold.yaml is an absolute, symlink-resolved path that contains all watched files","Normalize event file paths (filepath.Clean / EvalSymlinks) before calling syncItem","Check that the jib/docker sync diff is generated against the same workspace root configured in skaffold.yaml"],"exampleFix":"// before\nworkspace: ~/project/app   # tilde not expanded, mismatch with events\n// after\nworkspace: /home/dev/project/app","handlingStrategy":"validation","validationCode":"for _, f := range files {\n    if _, err := filepath.Rel(contextWd, f); err != nil {\n        return fmt.Errorf(\"event file %s not under context %s\", f, contextWd)\n    }\n}","typeGuard":"func underContext(contextWd, f string) bool {\n    rel, err := filepath.Rel(contextWd, f)\n    return err == nil && rel != \"..\" && !strings.HasPrefix(rel, \"..\"+string(filepath.Separator))\n}","tryCatchPattern":"_, err := sync.Sync(ctx, out, names, item)\nif err != nil {\n    if strings.Contains(err.Error(), \"can't be found relative to context\") {\n        log.Warnf(\"dropping out-of-context file from sync: %v\", err)\n        return nil\n    }\n    return err\n}","preventionTips":["Resolve symlinks and tilde in workspace config before generating sync diffs","Confirm jib/docker sync diff paths share the configured workspace root","Filter watcher events to files under the artifact workspace before syncing"],"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"}