gastownhall/beads · error

backfill custom_types: %w

Error message

backfill custom_types: %w

What it means

Wrapper produced by ensureBackfilledCustomStatusesCustomTypes when backfillCustomTypes — which copies custom issue types from the config key 'types.custom' into the custom_types table — fails. The underlying error (SQL failure reading config/custom_types or inserting rows) is preserved via %w. MigrateUp calls this, so a database schema or config problem surfaces here during migration.

Source

Thrown at internal/storage/schema/backfill.go:17

package schema

import (
	"context"
	"database/sql"
	"fmt"
	"log"
	"strings"

	"github.com/steveyegge/beads/internal/storage/issueops"
	"github.com/steveyegge/beads/internal/types"
)

func ensureBackfilledCustomStatusesCustomTypes(ctx context.Context, db DBConn) (bool, error) {
	typesWrote, err := backfillCustomTypes(ctx, db)
	if err != nil {
		return typesWrote, fmt.Errorf("backfill custom_types: %w", err)
	}
	statusesWrote, err := backfillCustomStatuses(ctx, db)
	if err != nil {
		return typesWrote || statusesWrote, fmt.Errorf("backfill custom_statuses: %w", err)
	}
	return typesWrote || statusesWrote, nil
}

func needsBackfilledCustomStatusesCustomTypes(ctx context.Context, db DBConn) (bool, error) {
	typesNeed, err := needsCustomTypesBackfill(ctx, db)
	if err != nil {
		return false, fmt.Errorf("custom_types: %w", err)
	}
	statusesNeed, err := needsCustomStatusesBackfill(ctx, db)
	if err != nil {
		return false, fmt.Errorf("custom_statuses: %w", err)
	}
	return typesNeed || statusesNeed, nil

View on GitHub (pinned to 71377f2769)

Solutions

  1. Run the full MigrateUp flow so numbered migrations create custom_types before the backfill runs.
  2. Check the Dolt server is reachable and the database isn't locked; retry.
  3. Verify the DB user has SELECT on config and custom_types plus INSERT on custom_types.
  4. Inspect the wrapped driver error for the exact failing statement and fix accordingly (e.g. restore the config table).
Defensive patterns

Strategy: retry

Validate before calling

// Confirm prerequisite tables exist before MigrateUp's backfill stage
for _, t := range []string{"custom_types", "config"} {
	var n int
	if err := db.QueryRowContext(ctx, `SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?`, t).Scan(&n); err != nil || n == 0 {
		return fmt.Errorf("table %s missing; migrations incomplete", t)
	}
}

Try / catch

err := migrateUp(ctx)
if err != nil && strings.Contains(err.Error(), "backfill custom_types:") {
	if isTransient(err) {
		err = migrateUp(ctx) // backfill is count-gated and idempotent
	}
}

Prevention

When it happens

Trigger: backfillCustomTypes errors while running SELECT COUNT(*) FROM custom_types, reading config key 'types.custom', or INSERT IGNORE INTO custom_types — missing table, connection failure, or permission denial during MigrateUp.

Common situations: Fresh or partially migrated database where custom_types doesn't exist yet; DB user lacking SELECT/INSERT privileges; locked or corrupted Dolt database; connection dropped mid-migration.

Related errors


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