{"record":{"id":"8461f70008a5c416","repo":"ipfs/kubo","slug":"import-failed-w","errorCode":null,"errorMessage":"import failed: %w","messagePattern":"import failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/dag/import.go","lineNumber":112,"sourceCode":"\t\t// Default 100MiB. When setting block size to 1MiB, we can add\n\t\t// ~100 nodes maximum. With default 256KiB block-size, we will\n\t\t// hit the max nodes limit at 32MiB.p\n\t\tipld.MaxSizeBatchOption(int(cfg.Import.BatchMaxSize.WithDefault(config.DefaultBatchMaxSize))),\n\t)\n\n\troots := cid.NewSet()\n\tvar blockCount, blockBytesCount uint64\n\n\t// remember last valid block and provide a meaningful error message\n\t// when a truncated/mangled CAR is being imported\n\timportError := func(previous blocks.Block, current blocks.Block, err error) error {\n\t\tif current != nil {\n\t\t\treturn fmt.Errorf(\"import failed at block %q: %w\", current.Cid(), err)\n\t\t}\n\t\tif previous != nil {\n\t\t\treturn fmt.Errorf(\"import failed after block %q: %w\", previous.Cid(), err)\n\t\t}\n\t\treturn fmt.Errorf(\"import failed: %w\", err)\n\t}\n\n\tit := req.Files.Entries()\n\tfor it.Next() {\n\t\tfile := files.FileFromEntry(it)\n\t\tif file == nil {\n\t\t\treturn errors.New(\"expected a file handle\")\n\t\t}\n\n\t\t// import blocks\n\t\terr = func() error {\n\t\t\t// wrap a defer-closer-scope\n\t\t\t//\n\t\t\t// every single file in it() is already open before we start\n\t\t\t// just close here sooner rather than later for neatness\n\t\t\t// and to surface potential errors writing on closed fifos\n\t\t\t// this won't/can't help with not running out of handles\n\t\t\tdefer file.Close()","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/dag/import.go#L94-L130","documentation":"The fallback message from importError when neither a current nor a previous block is known: `ipfs dag import` failed at the CAR level before any block could be read, so there is no CID context to report.","triggerScenarios":"CAR whose header is corrupt or unreadable, empty file passed to `ipfs dag import`, or an I/O error reading the very first record.","commonSituations":"Passing a non-CAR file (e.g. plain UnixFS file or JSON) to `ipfs dag import`; zero-byte file from a failed transfer; CARv1/2 version confusion.","solutions":["Verify the file is actually a CAR (`ipfs dag stats` won't help; check magic bytes / use `ipfs car ls` if available)","Re-download or re-export the CAR","Use `ipfs dag put`/`ipfs add` instead if the input was never a CAR"],"exampleFix":"// before\nipfs dag import random.bin\n// error: import failed: ...\n// after\nipfs dag import real-export.car","handlingStrategy":"validation","validationCode":"// check CAR magic bytes before import\nf, _ := os.Open(path)\ndefer f.Close()\nhdr := make([]byte, 2)\nio.ReadFull(f, hdr) // CARv1/2 start with 0x0a 0xa1 or 0x0a 0xa2 (varint + version)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only pass files produced by ipfs dag export / go-car to dag import","Check the file is non-empty and begins with valid CAR bytes","Distinguish dag import (CARs) from dag put / ipfs add (raw data)"],"tags":["car","dag-import","invalid-input"],"backgroundTag":"invalid-car-header","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}