gastownhall/beads · error

import failed: %w

Error message

import failed: %w

What it means

The core issue-writing pipeline importIssuesCore failed during classic import; the whole operation is reported as `import failed: <cause>`. This covers dedup/prefix validation, guarded upserts, and any store-level error raised while writing issue rows.

Source

Thrown at cmd/bd/import.go:344

		applyImportDryRunClassification(&result, classification)
		return renderImportDryRun(result, len(memories), source, dedupHits)
	}

	// Import memories
	for _, mem := range memories {
		storageKey := kvPrefix + memoryPrefix + mem.Key
		if err := store.SetConfig(ctx, storageKey, mem.Value); err != nil {
			return fmt.Errorf("failed to import memory %q: %w", mem.Key, err)
		}
		result.Memories++
	}

	// Import issues
	if len(issues) > 0 {
		opts := ImportOptions{SkipPrefixValidation: true, AllowStale: importAllowStale}
		importResult, err := importIssuesCore(ctx, "", store, issues, opts)
		if err != nil {
			return fmt.Errorf("import failed: %w", err)
		}
		applyImportOutcome(&result, importResult)
	}

	if result.Created > 0 || result.Memories > 0 {
		commitMsg := fmt.Sprintf("bd import: %d issues", result.Created)
		if result.Memories > 0 {
			commitMsg += fmt.Sprintf(", %d memories", result.Memories)
		}
		commitMsg += fmt.Sprintf(" from %s", filepath.Base(source))
		if err := store.Commit(ctx, commitMsg); err != nil {
			// An import can be a working-set no-op: re-importing an
			// identical snapshot, or equal-timestamp rows whose guarded
			// upsert kept every local column (bd-hj85c).
			if !strings.Contains(err.Error(), "nothing to commit") {
				return fmt.Errorf("commit: %w", err)
			}
		}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Read the wrapped inner error after `import failed:` for the specific cause
  2. Re-export from source with `bd export` so records match the current schema/prefix
  3. Use `bd import --dry-run` first to classify what would fail before committing
  4. If staleness is the cause, re-run with `--allow-stale` after confirming the snapshot is acceptable

Example fix

// before
bd import old-export.jsonl   # import failed: prefix mismatch (bd- vs acme-)
// after
# fix prefix in records to match local config.yaml issue_prefix
bd import --dry-run old-export.jsonl && bd import old-export.jsonl
Defensive patterns

Strategy: try-catch

Validate before calling

bd import --dry-run data.jsonl   # classify before committing
jq -e '.issue_prefix' .beads/config.yaml >/dev/null 2>&1 || bd config get issue_prefix

Try / catch

if ! bd import data.jsonl 2>err.log; then
  grep -o 'import failed: .*' err.log   # read inner cause (prefix, staleness, dup)
fi

Prevention

When it happens

Trigger: `bd import` with issues where importIssuesCore errors: prefix validation failure (mismatched issue prefixes vs configured prefix, bypassed here only via SkipPrefixValidation on other paths), stale imports without AllowStale, constraint violations, or store write errors.

Common situations: Importing an export from a repo with a different issue_prefix; importing stale snapshots over a database that advanced; duplicate ID conflicts with different content; database lock contention.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/4ce660abec09ffca. Report an issue: GitHub.