{"record":{"id":"bded1c20f0cbea6d","repo":"caddyserver/caddy","slug":"reading-archive-v","errorCode":null,"errorMessage":"reading archive: %v","messagePattern":"reading archive: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/storagefuncs.go","lineNumber":118,"sourceCode":"\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)\n\t\t}\n\n\t\terr = stor.Store(ctx, hdr.Name, b)\n\t\tif err != nil {\n\t\t\treturn caddy.ExitCodeFailedQuit, fmt.Errorf(\"reading archive: %v\", err)\n\t\t}\n\t}\n\n\tfmt.Println(\"Successfully imported storage\")\n\treturn caddy.ExitCodeSuccess, nil\n}\n\nfunc cmdExportStorage(fl Flags) (int, error) {","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/cmd/storagefuncs.go#L100-L136","documentation":"During 'caddy storage import', tar.Reader.Next() failed with something other than io.EOF while advancing to the next archive entry. The input opened fine but is not a valid (uncompressed) tar stream — most often it is gzip-compressed (the code applies no decompression), truncated, or not a tar at all.","triggerScenarios":"Feeding a .tar.gz to --input (the reader expects plain tar); a tar truncated by an interrupted 'caddy storage export'; passing an arbitrary file (JSON config, zip) as --input.","commonSituations":"Admin compresses exports to save space (gzip -9 storage.tar) then imports without decompressing; scp transfer cut short; exporting to '-' piped through a tool that mangled the bytes.","solutions":["If compressed, decompress first: gunzip -c storage.tar.gz > storage.tar, then import the plain tar","Verify integrity: tar -tf storage.tar should list entries without errors","Re-export from the source storage if the archive is truncated","Stream directly between instances: caddy storage export ... --output - | caddy storage import ... --input -"],"exampleFix":"# before\ncaddy storage import --config caddy.json --input storage.tar.gz\n# error: reading archive: gzip: invalid header (or tar format error)\n\n# after\ngunzip -c storage.tar.gz | caddy storage import --config caddy.json --input -","handlingStrategy":"validation","validationCode":"# verify the archive is a plain, readable tar before importing\ntar -tf storage.tar >/dev/null && echo ok || echo 'not a valid tar (gzip? corrupt?)'\n# decompress if needed: gunzip -c storage.tar.gz > storage.tar","typeGuard":null,"tryCatchPattern":null,"preventionTips":["The importer reads plain tar only — always gunzip .tar.gz first","Validate archives with 'tar -tf' after transfer","Pipe export straight into import to avoid intermediate format mistakes: export --output - | import --input -"],"tags":["storage","import","tar","archive"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}