gastownhall/beads · error

batch create molecules: %w

Error message

batch create molecules: %w

What it means

LoadAll batch-creates all validated molecules through storage in one call. If CreateIssuesWithFullOptions fails for any of the new mol-* issues, the storage error is wrapped with this message and loading aborts, returning 0 loaded.

Source

Thrown at internal/molecules/molecules.go:155

			// Already exists - skip (or could update if newer)
			debug.Logf("molecule %s already exists, skipping", mol.ID)
			continue
		}

		newMolecules = append(newMolecules, mol)
	}

	if len(newMolecules) == 0 {
		return 0, nil
	}

	// Use batch creation with prefix validation skipped.
	// Molecules have their own ID namespace (mol-*) independent of project prefix.
	opts := storage.BatchCreateOptions{
		SkipPrefixValidation: true, // Molecules use their own prefix
	}
	if err := l.store.CreateIssuesWithFullOptions(ctx, newMolecules, "molecules-loader", opts); err != nil {
		return 0, fmt.Errorf("batch create molecules: %w", err)
	}
	return len(newMolecules), nil
}

// loadMoleculesFromFile loads molecules from a JSONL file.
func loadMoleculesFromFile(path string) ([]*types.Issue, error) {
	// Check if file exists
	if _, err := os.Stat(path); os.IsNotExist(err) {
		return nil, nil
	}

	// #nosec G304 - path is constructed from known safe locations
	file, err := os.Open(path)
	if err != nil {
		return nil, fmt.Errorf("failed to open %s: %w", path, err)
	}
	defer file.Close()

View on GitHub (pinned to 71377f2769)

Solutions

  1. Read the wrapped inner error (%w) to identify the storage cause; fix that first (e.g. remove the duplicate mol- ID from the JSONL).
  2. Verify the store is initialized, writable, and reachable before running LoadAll.
  3. Re-run LoadAll after correcting the input files or storage.
Defensive patterns

Strategy: try-catch

Try / catch

n, err := LoadAll(ctx, store, dir)
if err != nil {
    var storageErr *storage.Error
    if errors.As(err, &storageErr) {
        return fmt.Errorf("molecule insert failed: %w", storageErr)
    }
    return err
}

Prevention

When it happens

Trigger: Any storage-layer failure inside CreateIssuesWithFullOptions during LoadAll's molecule load: DB closed/corrupt, constraint violation (duplicate mol- ID), or transaction failure. Prefix validation is skipped because molecules use their own mol- prefix.

Common situations: Duplicate molecule IDs across multiple molecules.jsonl files; Dolt/DB connection dropped mid-load; loading into an uninitialized or read-only store.

Related errors


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