{"record":{"id":"6a7f77ae85d37836","repo":"gastownhall/beads","slug":"scan-constraint-violation-w","errorCode":null,"errorMessage":"scan constraint violation: %w","messagePattern":"scan constraint violation: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/conflicts.go","lineNumber":532,"sourceCode":"\n// constraintViolationCounts lists the tables carrying outstanding constraint\n// violations. mergesettle.go repairs the FK-cascade class on the auto path;\n// anything it declined lands here, blocking the commit.\nfunc constraintViolationCounts(ctx context.Context, db DBConn) ([]storage.ConstraintViolation, error) {\n\trows, err := db.QueryContext(ctx,\n\t\t\"SELECT `table`, num_violations FROM dolt_constraint_violations WHERE num_violations > 0\")\n\tif err != nil {\n\t\tif isMissingSystemTable(err) {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"query constraint violations: %w\", err)\n\t}\n\tdefer func() { _ = rows.Close() }()\n\tvar out []storage.ConstraintViolation\n\tfor rows.Next() {\n\t\tvar v storage.ConstraintViolation\n\t\tif err := rows.Scan(&v.Table, &v.Count); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"scan constraint violation: %w\", err)\n\t\t}\n\t\tout = append(out, v)\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"iterate constraint violations: %w\", err)\n\t}\n\treturn out, nil\n}\n\n// isMissingSystemTable reports whether err is dolt/MySQL's \"table does not\n// exist\". Matched on the message because the embedded engine and the MySQL\n// driver report it as different error types.\nfunc isMissingSystemTable(err error) bool {\n\tif err == nil {\n\t\treturn false\n\t}\n\tmsg := strings.ToLower(err.Error())\n\treturn strings.Contains(msg, \"table not found\") ||","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/conflicts.go#L514-L550","documentation":"While iterating dolt_constraint_violations, a row could not be scanned into storage.ConstraintViolation{Table, Count} — the table or num_violations value was NULL or of an incompatible type. This signals schema/version drift in the system table or corrupted violation records rather than normal operation.","triggerScenarios":"GetMergeBlockers iterating dolt_constraint_violations rows where table is NULL or num_violations is not integer-compatible — after engine upgrades, metadata corruption, or when the serving engine returns different column types than bd expects.","commonSituations":"Mixed dolt versions writing/reading the violations table; manual manipulation of dolt system tables; replicas or snapshots with partially written violation metadata.","solutions":["Inspect the table manually (SELECT *) to locate the malformed row and repair or clear it by resolving the underlying FK violation.","Verify dolt engine version compatibility with bd; upgrade so column types match what the scan expects.","Abort and redo the merge if the violations state is inconsistent, letting dolt rewrite the table.","Resolve the specific table's constraint violations directly so its row disappears from the list."],"exampleFix":"// before: strict scan into typed fields\nvar v storage.ConstraintViolation\nif err := rows.Scan(&v.Table, &v.Count); err != nil { ... }\n// after: tolerant scan with null checks\nvar table sql.NullString\nvar count sql.NullInt64\nif err := rows.Scan(&table, &count); err != nil { ... }\nif !table.Valid || !count.Valid { continue } // skip malformed row","handlingStrategy":"type-guard","validationCode":"// Detect malformed violation rows before full resolution:\nrows, _ := db.QueryContext(ctx, \"SELECT `table`, num_violations FROM dolt_constraint_violations\")\nfor rows.Next() {\n  var t sql.NullString; var c sql.NullInt64\n  if rows.Scan(&t, &c) != nil || !t.Valid || !c.Valid { /* corrupt row */ }\n}","typeGuard":"func validViolationRow(t sql.NullString, c sql.NullInt64) bool { return t.Valid && c.Valid && c.Int64 > 0 }","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"scan constraint violation\") {\n  log.Printf(\"malformed dolt_constraint_violations row: %v — inspect manually\", err)\n}","preventionTips":["Keep dolt engine versions aligned across clients.","Don't modify dolt system tables directly.","After engine upgrades, re-verify system-table schemas before merge operations."],"tags":["dolt","constraint-violations","scan-error","type-mismatch"],"backgroundTag":"sql-scan-type-mismatch","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}