{"record":{"id":"021805afc065df05","repo":"gastownhall/beads","slug":"scan-constraint-violation-w-021805","errorCode":null,"errorMessage":"scan constraint violation: %w","messagePattern":"scan constraint violation: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/mergesettle.go","lineNumber":913,"sourceCode":"\t\treturn false, true, nil\n\t}\n\treturn true, true, nil\n}\n\n// constraintViolationTables lists the tables with outstanding constraint\n// violations in the working set.\nfunc constraintViolationTables(ctx context.Context, db DBConn) ([]string, error) {\n\trows, err := db.QueryContext(ctx,\n\t\t\"SELECT `table` FROM dolt_constraint_violations WHERE num_violations > 0\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"query constraint violations: %w\", err)\n\t}\n\tdefer rows.Close()\n\tvar tables []string\n\tfor rows.Next() {\n\t\tvar t string\n\t\tif err := rows.Scan(&t); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"scan constraint violation: %w\", err)\n\t\t}\n\t\ttables = append(tables, t)\n\t}\n\treturn tables, rows.Err()\n}\n\n// violationsAreIssueFKOnly reports whether every constraint violation recorded\n// for table is a foreign-key violation referencing issues — the only class the\n// cascade repair understands. violation_info is Dolt's JSON descriptor; its\n// ReferencedTable names the FK's parent.\nfunc violationsAreIssueFKOnly(ctx context.Context, db DBConn, table string) (bool, error) {\n\t// table is from the fixed fkCascadeRepairDeletes allowlist, never user input.\n\t//nolint:gosec // G202: hardcoded table name.\n\trows, err := db.QueryContext(ctx,\n\t\t\"SELECT violation_type, violation_info FROM dolt_constraint_violations_\"+table)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"query %s constraint violations: %w\", table, err)\n\t}","sourceCodeStart":895,"sourceCodeEnd":931,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/mergesettle.go#L895-L931","documentation":"While scanning rows of the dolt_constraint_violations listing, a row could not be read into a single string column (the table name). This indicates the rowset's column shape differs from expected — the engine returned extra or differently-typed columns. Scanning stops and the partial table list is discarded with this wrapped error.","triggerScenarios":"dolt_constraint_violations returns rows whose shape doesn't match one string column — e.g. Dolt changed the system table's schema (added columns) or a NULL table name is returned.","commonSituations":"Engine upgrade changing the violations table layout; mixed server/embedded behaviors; corrupted merge metadata row.","solutions":["Inspect the wrapped %w error for 'expected N destination arguments' (column count drift) vs conversion errors.","Run the query manually to see the actual columns returned by your Dolt version.","Upgrade beads to a version matching your Dolt engine's violations schema.","Pin the Dolt engine version beads was built and tested against."],"exampleFix":"// before\nvar t string\nif err := rows.Scan(&t); err != nil {\n    return nil, fmt.Errorf(\"scan constraint violation: %w\", err)\n}\n// after: scan by column count flexibility\nvar t string\ncols, _ := rows.Columns()\nif len(cols) == 1 {\n    err = rows.Scan(&t)\n} else {\n    var extra sql.RawBytes\n    args := []any{&t, &extra}\n    err = rows.Scan(args...) // adapt to engine layout\n}\nif err != nil {\n    return nil, fmt.Errorf(\"scan constraint violation: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"cols, _ := db.Query(\"SELECT `table` FROM dolt_constraint_violations LIMIT 0\")\n// inspect cols.Columns() to confirm a single string column before scanning","typeGuard":null,"tryCatchPattern":"tables, err := constraintViolationTables(ctx, db)\nif err != nil && strings.Contains(err.Error(), \"scan constraint violation\") {\n    // system-table schema drift: fall back to manual inspection\n    return manualViolationListing()\n}","preventionTips":["Re-check violations-table layout after Dolt upgrades","Pin engine versions in deployment","Avoid mixing server and embedded engines against the same repo"],"tags":["dolt","sql-scan","constraint-violations"],"backgroundTag":"sql-scan-column-mismatch","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}