{"record":{"id":"5fdb522d6463f1c5","repo":"ipfs/kubo","slug":"import-failed-after-block-q-w","errorCode":null,"errorMessage":"import failed after block %q: %w","messagePattern":"import failed after block %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/dag/import.go","lineNumber":110,"sourceCode":"\t\t// Default: 128. Means 128 file descriptors needed in flatfs\n\t\tipld.MaxNodesBatchOption(int(cfg.Import.BatchMaxNodes.WithDefault(config.DefaultBatchMaxNodes))),\n\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","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/dag/import.go#L92-L128","documentation":"Variant of the import-failure wrapper used when the current block cannot be identified (e.g. the CAR iterator fails before a block is read). Kubo reports the CID of the last valid block seen, as `import failed after block %q: %w`, so users know how far the import got before failing.","triggerScenarios":"Truncated CAR where the iterator hits EOF mid-record (no complete next block to attribute the failure to); unreadable CAR header/section boundaries after at least one valid block.","commonSituations":"CAR cut off by disk-full, cancelled transfer, or partial HTTP download; reading a CAR that is still being written by `ipfs dag export`.","solutions":["Re-acquire the full CAR file; it is truncated","Check the source file size against expected size / CARv2 header","Wait for the producing export to finish before importing","Find the last good root and re-export remaining DAG separately"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// ensure source transfer completed before import\nif expectedSize, ok := manifest[carPath]; ok {\n    if st.Size() != expectedSize {\n        return fmt.Errorf(\"CAR truncated: got %d want %d\", st.Size(), expectedSize)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match file size against a manifest or Content-Length","Don't import a CAR while its producer is still writing","Re-download on any truncated-file suspicion"],"tags":["car","dag-import","truncated-data"],"backgroundTag":"truncated-car-file","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"}