ipfs/kubo · error

import failed after block %q: %w

Error message

import failed after block %q: %w

What it means

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.

Source

Thrown at core/commands/dag/import.go:110

		// Default: 128. Means 128 file descriptors needed in flatfs
		ipld.MaxNodesBatchOption(int(cfg.Import.BatchMaxNodes.WithDefault(config.DefaultBatchMaxNodes))),
		// Default 100MiB. When setting block size to 1MiB, we can add
		// ~100 nodes maximum. With default 256KiB block-size, we will
		// hit the max nodes limit at 32MiB.p
		ipld.MaxSizeBatchOption(int(cfg.Import.BatchMaxSize.WithDefault(config.DefaultBatchMaxSize))),
	)

	roots := cid.NewSet()
	var blockCount, blockBytesCount uint64

	// remember last valid block and provide a meaningful error message
	// when a truncated/mangled CAR is being imported
	importError := func(previous blocks.Block, current blocks.Block, err error) error {
		if current != nil {
			return fmt.Errorf("import failed at block %q: %w", current.Cid(), err)
		}
		if previous != nil {
			return fmt.Errorf("import failed after block %q: %w", previous.Cid(), err)
		}
		return fmt.Errorf("import failed: %w", err)
	}

	it := req.Files.Entries()
	for it.Next() {
		file := files.FileFromEntry(it)
		if file == nil {
			return errors.New("expected a file handle")
		}

		// import blocks
		err = func() error {
			// wrap a defer-closer-scope
			//
			// every single file in it() is already open before we start
			// just close here sooner rather than later for neatness
			// and to surface potential errors writing on closed fifos

View on GitHub (pinned to 329838acdf)

Solutions

  1. Re-acquire the full CAR file; it is truncated
  2. Check the source file size against expected size / CARv2 header
  3. Wait for the producing export to finish before importing
  4. Find the last good root and re-export remaining DAG separately
Defensive patterns

Strategy: validation

Validate before calling

// ensure source transfer completed before import
if expectedSize, ok := manifest[carPath]; ok {
    if st.Size() != expectedSize {
        return fmt.Errorf("CAR truncated: got %d want %d", st.Size(), expectedSize)
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: CAR cut off by disk-full, cancelled transfer, or partial HTTP download; reading a CAR that is still being written by `ipfs dag export`.

Related errors


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/5fdb522d6463f1c5. Report an issue: GitHub.