{"record":{"id":"fa3e2866edd5bd36","repo":"caddyserver/caddy","slug":"opening-input-file-v","errorCode":null,"errorMessage":"opening input file: %v","messagePattern":"opening input file: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/storagefuncs.go","lineNumber":105,"sourceCode":"\t\tif err != nil {\n\t\t\treturn caddy.ExitCodeFailedStartup, err\n\t\t}\n\t\tstor, err = val.(caddy.StorageConverter).CertMagicStorage()\n\t\tif err != nil {\n\t\t\treturn caddy.ExitCodeFailedStartup, err\n\t\t}\n\t} else {\n\t\tstor = caddy.DefaultStorage\n\t}\n\n\t// setup input\n\tvar f *os.File\n\tif importStorageCmdImportFile == \"-\" {\n\t\tf = os.Stdin\n\t} else {\n\t\tf, err = os.Open(importStorageCmdImportFile)\n\t\tif err != nil {\n\t\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"opening input file: %v\", err)\n\t\t}\n\t\tdefer f.Close()\n\t}\n\n\t// store each archive element\n\ttr := tar.NewReader(f)\n\tfor {\n\t\thdr, err := tr.Next()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn caddy.ExitCodeFailedQuit, fmt.Errorf(\"reading archive: %v\", err)\n\t\t}\n\n\t\tb, err := io.ReadAll(tr)\n\t\tif err != nil {\n\t\t\treturn caddy.ExitCodeFailedQuit, fmt.Errorf(\"reading archive: %v\", err)","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/cmd/storagefuncs.go#L87-L123","documentation":"cmdImportStorage ('caddy storage import') failed at os.Open of the --input file (unless '-' was passed for stdin). The wrapped error is a standard os.PathError: usually 'no such file or directory' or 'permission denied'. Nothing has been imported yet at this point.","triggerScenarios":"Passing a wrong path to --input; passing a gzip-compressed archive is fine here (path opens) but a missing/unreadable file triggers this; relative path resolved from the wrong cwd; input file owned by another user.","commonSituations":"Importing a storage tar produced on another server with a typo'd path; running caddy as a service user without read access to /root/backup.tar; SELinux denying read of a file in /tmp.","solutions":["Verify the path exists and is readable: ls -l <input.tar>","Use an absolute path for --input to avoid cwd ambiguity","Fix permissions/ownership or copy the file to a location the invoking user can read","To stream from another command, pass --input - and pipe the tar in"],"exampleFix":"# before\ncaddy storage import --config caddy.json --input backup.tar\n# error: opening input file: open backup.tar: no such file or directory\n\n# after\ncaddy storage import --config caddy.json --input /var/backups/caddy/storage.tar","handlingStrategy":"validation","validationCode":"INPUT=/var/backups/caddy/storage.tar\n[ -r \"$INPUT\" ] || { echo \"missing/unreadable: $INPUT\"; exit 1; }\nfile \"$INPUT\"   # should report: POSIX tar archive (not gzip!)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use absolute paths for --input","Pre-check readability with test -r before scripted imports","Keep export archives uncompressed plain tar to match the importer"],"tags":["storage","import","filesystem","cli"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}