{"record":{"id":"dbc2c49f23bce278","repo":"juicedata/juicefs","slug":"failed-to-open-file-s-w","errorCode":null,"errorMessage":"failed to open file %s: %w","messagePattern":"failed to open file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/load.go","lineNumber":263,"sourceCode":"\t\t\treturn err\n\t\t}\n\t}\n\tif format, err := m.Load(true); err == nil {\n\t\tif format.SecretKey == \"removed\" {\n\t\t\tlogger.Warnf(\"secret key was removed; please correct it with `config` command\")\n\t\t}\n\t} else {\n\t\treturn err\n\t}\n\tlogger.Infof(\"load metadata from %q succeed\", src)\n\treturn nil\n}\n\nfunc statBak(ctx *cli.Context, path string) error {\n\tlogger.Infof(\"load backup from %q\", path)\n\tfp, err := os.Open(path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open file %s: %w\", path, err)\n\t}\n\tdefer fp.Close()\n\n\tif !ctx.IsSet(\"offset\") {\n\t\treturn showBakSummary(ctx, fp, false)\n\t}\n\n\toffset := ctx.Int64(\"offset\")\n\tif offset == -1 {\n\t\treturn showBakSummary(ctx, fp, true)\n\t}\n\n\treturn showBakDetail(ctx, fp, offset)\n}\n\nfunc showBakSummary(ctx *cli.Context, fp *os.File, withOffset bool) error {\n\tbak := &meta.BakFormat{}\n\tfooter, err := bak.ReadFooter(fp)","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/load.go#L245-L281","documentation":"`statBak` (used by `juicefs status`-style inspection of a backup via load's subcommands) opens the backup file with os.Open. If the open fails, the error is wrapped as `failed to open file <path>: <error>`. Unlike the stat error, this is raised at open time and reports the OS-level reason (ENOENT, EACCES, EISDIR, etc.).","triggerScenarios":"`juicefs load` backup-inspection path (statBak) invoked with a backup path that does not exist, is a directory, or is not readable by the current user.","commonSituations":"Typo'd backup filename; passing a directory instead of a file; file created by root but inspected as another user; backup on a detached/unmounted volume.","solutions":["Verify the path with `ls -l <path>`; fix typos and ensure it is a regular file","Check permissions (`sudo` if the backup was written by root)","Ensure the filesystem/volume holding the backup is mounted","Pass the correct backup file produced by `juicefs dump`/`load`"],"exampleFix":"// before\njuicefs load --stat meta.sqlite3 /backups/\n// after\njuicefs load --stat meta.sqlite3 /backups/jfs-backup-20260906.json","handlingStrategy":"validation","validationCode":"fi, err := os.Stat(backupPath)\nif err != nil { return err }\nif fi.IsDir() { return fmt.Errorf(\"%s is a directory\", backupPath) }\nif err := unix.Access(backupPath, unix.R_OK); err != nil {\n    return fmt.Errorf(\"%s not readable\", backupPath)\n}","typeGuard":null,"tryCatchPattern":"if err := statBak(ctx, path); err != nil {\n    if strings.Contains(err.Error(), \"failed to open file\") {\n        var pe *fs.PathError\n        log.Fatalf(\"open failed (ENOENT/EACCES?): %v\", err)\n    }\n}","preventionTips":["Check file existence and read permission before inspection commands","Pass regular files, not directories or globs","Align user permissions with whoever created the backup"],"tags":["filesystem","file-open","backup-restore"],"backgroundTag":"file-open-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}