gastownhall/beads · error
query %s constraint violations: %w
Error message
query %s constraint violations: %w
What it means
violationsAreIssueFKOnly inspects the per-table dolt_constraint_violations_<table> rows to confirm all violations are foreign-key violations before auto-repair deletes anything. If the SELECT against that table fails, this wrapped error is returned and repair refuses to proceed (safety-first behavior).
Source
Thrown at internal/storage/versioncontrolops/mergesettle.go:930
if err := rows.Scan(&t); err != nil {
return nil, fmt.Errorf("scan constraint violation: %w", err)
}
tables = append(tables, t)
}
return tables, rows.Err()
}
// violationsAreIssueFKOnly reports whether every constraint violation recorded
// for table is a foreign-key violation referencing issues — the only class the
// cascade repair understands. violation_info is Dolt's JSON descriptor; its
// ReferencedTable names the FK's parent.
func violationsAreIssueFKOnly(ctx context.Context, db DBConn, table string) (bool, error) {
// table is from the fixed fkCascadeRepairDeletes allowlist, never user input.
//nolint:gosec // G202: hardcoded table name.
rows, err := db.QueryContext(ctx,
"SELECT violation_type, violation_info FROM dolt_constraint_violations_"+table)
if err != nil {
return false, fmt.Errorf("query %s constraint violations: %w", table, err)
}
defer rows.Close()
for rows.Next() {
var vtype string
var vinfo any
if err := rows.Scan(&vtype, &vinfo); err != nil {
return false, fmt.Errorf("scan %s constraint violation: %w", table, err)
}
if vtype != "foreign key" {
return false, nil
}
// Server mode returns violation_info as JSON text; the embedded engine
// hands back the driver's native value (e.g. merge.FkCVMeta), which
// marshals to the same JSON.
var infoJSON []byte
switch v := vinfo.(type) {
case []byte:
infoJSON = vView on GitHub (pinned to 71377f2769)
Solutions
- Check the wrapped %w error: 'doesn't exist' typically means there are no violations for this table — safe to skip.
- Confirm dolt_constraint_violations lists this table with num_violations > 0 before reading the per-table violations.
- Retry once the merge transaction state is healthy.
- Align Dolt engine version with what beads supports.
Example fix
// before
rows, err := db.QueryContext(ctx, "SELECT violation_type, violation_info FROM dolt_constraint_violations_"+table)
if err != nil {
return false, fmt.Errorf("query %s constraint violations: %w", table, err)
}
// after: treat missing violations table as no-violations
rows, err := db.QueryContext(ctx, "SELECT violation_type, violation_info FROM dolt_constraint_violations_"+table)
if err != nil {
if strings.Contains(err.Error(), "doesn't exist") {
return true, nil
}
return false, fmt.Errorf("query %s constraint violations: %w", table, err)
} Defensive patterns
Strategy: validation
Validate before calling
var n int
_ = db.QueryRow("SELECT num_violations FROM dolt_constraint_violations WHERE `table` = ?", table).Scan(&n)
// only query per-table violations when n > 0 Type guard
func tableHasViolations(ctx context.Context, db DBConn, table string) bool {
var n int
_ = db.QueryRow("SELECT num_violations FROM dolt_constraint_violations WHERE `table` = ?", table).Scan(&n)
return n > 0
} Try / catch
ok, err := violationsAreIssueFKOnly(ctx, db, t)
if err != nil && strings.Contains(err.Error(), "constraint violations") {
if !tableHasViolations(ctx, db, t) {
continue // nothing to verify
}
return err
} Prevention
- Confirm the violations summary row before reading per-table violations
- Skip repair when the per-table violations table is absent
- Align engine versions to keep violation_info encoding stable
When it happens
Trigger: SELECT violation_type, violation_info FROM dolt_constraint_violations_<table> fails — the table doesn't exist because no violations were recorded, engine version mismatch on the per-table violations layout, or transaction/connection errors.
Common situations: Repair invoked when no violations table exists for that table (violations already resolved); Dolt versions naming or shaping the per-table violations table differently; server mode restricting system-table reads.
Related errors
- pull merge left constraint violations bd cannot auto-repair;
- creating wisp_dependencies for migration 0047: %w
- query constraint violations: %w
- scan constraint violation: %w
- iterate constraint violations: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/7fd4934880148d95.
Report an issue: GitHub.