{"record":{"id":"dc79f5fd9067f315","repo":"dagger/dagger","slug":"failed-to-stat-synctarget-dest-s-w","errorCode":null,"errorMessage":"failed to stat synctarget dest %s: %w","messagePattern":"failed to stat synctarget dest (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/client/filesync.go","lineNumber":292,"sourceCode":"\t// an error when path is a pre-existing directory.\n\tallowParentDirPath := opts.AllowParentDirPath\n\n\t// File exports specifically (as opposed to container tar exports) have an original filename that we will\n\t// use in the case where dest is a directory and allowParentDirPath is set, in which case we need to know\n\t// what to name the file underneath the pre-existing directory.\n\tfileOriginalName := opts.FileOriginalName\n\n\tvar destParentDir string\n\tvar finalDestPath string\n\tstat, err := os.Stat(absPath)\n\tswitch {\n\tcase errors.Is(err, os.ErrNotExist):\n\t\t// we are writing the file to a new path\n\t\tdestParentDir = filepath.Dir(absPath)\n\t\tfinalDestPath = absPath\n\tcase err != nil:\n\t\t// something went unrecoverably wrong if stat failed and it wasn't just because the path didn't exist\n\t\treturn fmt.Errorf(\"failed to stat synctarget dest %s: %w\", absPath, err)\n\tcase !stat.IsDir():\n\t\t// we are overwriting an existing file\n\t\tdestParentDir = filepath.Dir(absPath)\n\t\tfinalDestPath = absPath\n\tcase !allowParentDirPath:\n\t\t// we are writing to an existing directory, but allowParentDirPath is not set, so fail\n\t\treturn fmt.Errorf(\"destination %q is a directory; must be a file path unless allowParentDirPath is set\", absPath)\n\tdefault:\n\t\t// we are writing to an existing directory, and allowParentDirPath is set,\n\t\t// so write the file under the directory using the same file name as the source file\n\t\tif fileOriginalName == \"\" {\n\t\t\t// NOTE: we could instead just default to some name like container.tar or something if desired\n\t\t\treturn fmt.Errorf(\"cannot export container tar to existing directory %q\", absPath)\n\t\t}\n\t\tdestParentDir = absPath\n\t\tfinalDestPath = filepath.Join(destParentDir, fileOriginalName)\n\t}\n","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/engine/client/filesync.go#L274-L310","documentation":"In file/tar-stream mode, DiffCopy stats the destination path to decide how to write the file. If os.Stat fails for any reason other than 'does not exist', the situation is unrecoverable and the handler wraps the stat error with this message.","triggerScenarios":"os.Stat on the export destination fails with e.g. EACCES on a parent directory (cannot even check existence), ELOOP from a symlink cycle, ENAMETOOLONG, or I/O errors on the device.","commonSituations":"Destination nested under a directory the sync user cannot traverse; broken symlink loops after repeated exports; overly long paths from deep artifact trees (Windows MAX_PATH); failing network mounts.","solutions":["Fix permissions so the sync user can traverse every parent directory of the destination","Remove symlink loops or shorten the destination path","Verify the parent path exists and the mount is healthy","Export to a simpler, local, user-writable path to isolate the issue"],"exampleFix":"// before\nawait file.export(\"/mnt/nfs/very/deep/path/out.tar\") // flaky NFS\n// after\nawait file.export(filepath.Join(os.TempDir(), \"out.tar\"))\n// then move into place yourself","handlingStrategy":"validation","validationCode":"// walk every parent to catch EACCES/ELOOP before exporting\np := filepath.Dir(dest)\nfor {\n    if _, err := os.Stat(p); err != nil {\n        return fmt.Errorf(\"cannot stat %s: %w\", p, err)\n    }\n    parent := filepath.Dir(p)\n    if parent == p { break }\n    p = parent\n}","typeGuard":"func statable(path string) bool { _, err := os.Stat(path); return err == nil }","tryCatchPattern":null,"preventionTips":["Keep export destinations shallow and local","Avoid symlinks in destination paths","Use paths well under OS length limits (esp. Windows)","Verify mounts are healthy before long-running export jobs"],"tags":["filesystem","stat","filesync","path"],"backgroundTag":"stat-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"}