{"record":{"id":"ffef43c4a1ef3471","repo":"dagger/dagger","slug":"failed-to-resolve-target-path-s-w","errorCode":null,"errorMessage":"failed to resolve target path %s: %w","messagePattern":"failed to resolve target path (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/fsutil/copy/copy_linux.go","lineNumber":93,"sourceCode":"\t\tswitch {\n\t\tcase err == nil:\n\t\t\t// destination already exists, remove it\n\t\t\tif removeErr := os.Remove(target); removeErr != nil {\n\t\t\t\treturn false, fmt.Errorf(\"failed to remove existing destination file %s: %w\", target, removeErr)\n\t\t\t}\n\t\tcase errors.Is(err, os.ErrNotExist):\n\t\t\t// destination does not exist, proceed\n\t\tdefault:\n\t\t\treturn false, fmt.Errorf(\"failed to stat destination file %s: %w\", target, err)\n\t\t}\n\n\t\trealSource, err := c.sourcePathResolver(source)\n\t\tif err != nil {\n\t\t\treturn false, fmt.Errorf(\"failed to resolve source path %s: %w\", source, err)\n\t\t}\n\t\trealTarget, err := c.destPathResolver(target)\n\t\tif err != nil {\n\t\t\treturn false, fmt.Errorf(\"failed to resolve target path %s: %w\", target, err)\n\t\t}\n\n\t\terr = os.Link(realSource, realTarget)\n\t\tswitch {\n\t\tcase err == nil:\n\t\t\treturn true, nil\n\t\tcase errors.Is(err, unix.EXDEV), errors.Is(err, syscall.EMLINK):\n\t\t\t// either crossing filesystem boundary or too many links, fallback to copy\n\t\t\tslog.ExtraDebug(\"hardlink failed, falling back to copy\", \"source\", source, \"target\", target, \"error\", err)\n\t\tdefault:\n\t\t\treturn false, fmt.Errorf(\"failed to create hardlink from %s to %s: %w\", source, target, err)\n\t\t}\n\t}\n\n\tsrc, err := os.Open(source)\n\tif err != nil {\n\t\treturn false, errors.Wrapf(err, \"failed to open source %s\", source)\n\t}","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/internal/fsutil/copy/copy_linux.go#L75-L111","documentation":"copyFile calls c.destPathResolver(target) to map the destination path to its real (host) path before os.Link. A resolver failure is wrapped as \"failed to resolve target path %s\". Like the source resolver error, it indicates the destination could not be mapped to a real path the linker can use.","triggerScenarios":"destPathResolver returns an error — the target path is outside the configured destination root, the path traverses symlinks that escape it, or the custom resolver callback rejects the path.","commonSituations":"Destination path includes a symlinked directory resolving outside the copy root; programmatically-built target strings with \"..\" components escaping the root; resolver misconfigured with the wrong root prefix.","solutions":["Ensure the destination path is inside the configured destination root.","Clean the target path (filepath.Clean / avoid \"..\") so it stays within the destination root.","Fix or correctly configure the destPathResolver for the actual destination layout.","Disable the hardlink optimization to bypass path resolution entirely (plain copy is used instead)."],"exampleFix":"// before: target escapes the dest root via ..\ntarget := filepath.Join(destRoot, \"../escape\", name)\n// after\ntarget := filepath.Join(destRoot, filepath.Clean(name))","handlingStrategy":"validation","validationCode":"func withinRoot(root, p string) bool {\n    rel, err := filepath.Rel(root, p)\n    return err == nil && rel != \"..\" && !strings.HasPrefix(rel, \"..\"+string(filepath.Separator))\n}\n// call before copy:\nif !withinRoot(destRoot, targetPath) {\n    return fmt.Errorf(\"target %s escapes destination root\", targetPath)\n}","typeGuard":null,"tryCatchPattern":"if err := copier.Copy(ctx, src, dst); err != nil && strings.Contains(err.Error(), \"failed to resolve target path\") {\n    // clean/rebase the target path inside destRoot and retry\n}","preventionTips":["filepath.Clean destination paths and strip \"..\" components","Avoid symlinked directories in destination paths that escape the root","Configure the copier's dest root to match actual layout"],"tags":["filesystem","path-resolution","hardlink","copy","linux"],"backgroundTag":"path-resolution-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}