{"record":{"id":"1466ebebdaa0e4e1","repo":"ipfs/kubo","slug":"import-failed-at-block-q-w","errorCode":null,"errorMessage":"import failed at block %q: %w","messagePattern":"import failed at block %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/dag/import.go","lineNumber":107,"sourceCode":"\t// it is simply a way to relieve pressure on the blockstore\n\t// similar to pinner.Pin/pinner.Flush\n\tbatch := ipld.NewBatch(req.Context, api.Dag(),\n\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//","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/dag/import.go#L89-L125","documentation":"When `ipfs dag import` fails while reading/validating a block from a CAR, kubo wraps the underlying error with the CID of the block that could not be imported, giving a meaningful message for truncated or mangled CARs. The wrapper is `import failed at block %q: %w` when the current (failing) block is known.","triggerScenarios":"CAR file whose block bytes are corrupt, truncated mid-block, hash-mismatched, or unreadable during `ipfs dag import`; the failing block was successfully read enough to know its CID.","commonSituations":"Interrupted downloads producing truncated CARs; CARs modified in transit; bad blockstore writes from previous failed runs; CARv2 files read incorrectly.","solutions":["Re-download or re-export the CAR file; the copy is corrupt","Verify with `ipfs dag export <root> > fresh.car` and compare, or use a CAR verifier","Import with --stats to see how far the import progressed before failing","Use `ipfs car verify` (from go-car tooling) to locate all bad blocks"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// sanity-check CAR before import\nst, err := os.Stat(carPath)\nif err != nil || st.Size() == 0 {\n    return fmt.Errorf(\"CAR missing or empty: %s\", carPath)\n}\n// optionally verify hashes with go-car before importing","typeGuard":null,"tryCatchPattern":"// catch and surface the offending CID\nif err := run(\"ipfs\", \"dag\", \"import\", car); err != nil {\n    var cidStr string\n    if m := reBadBlock.FindStringSubmatch(errText(err)); m != nil {\n        cidStr = m[1] // re-export or re-download around this block\n    }\n    return fmt.Errorf(\"car corrupt at %s: %w\", cidStr, err)\n}","preventionTips":["Verify downloads (size/hash) before import","Never edit CAR files in place","Use CARv2 with integrity-checked producers"],"tags":["car","dag-import","corrupt-data"],"backgroundTag":"corrupt-car-block","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"}