{"record":{"id":"40d95955418124ae","repo":"gastownhall/beads","slug":"scan-dependency-w","errorCode":null,"errorMessage":"scan dependency: %w","messagePattern":"scan dependency: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/dependency_queries.go","lineNumber":1066,"sourceCode":"\t\t\tseen[id] = true\n\t\t\tblocked[id] = b != 0\n\t\t}\n\t\t_ = rows.Close()\n\t\tif err := rows.Err(); err != nil {\n\t\t\treturn fmt.Errorf(\"is_blocked rows from %s: %w\", table, err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// scanDependencyRow scans a single dependency row from a *sql.Rows.\nfunc scanDependencyRow(rows *sql.Rows) (*types.Dependency, error) {\n\tvar dep types.Dependency\n\tvar createdAt sql.NullTime\n\tvar metadata, threadID sql.NullString\n\n\tif err := rows.Scan(&dep.IssueID, &dep.DependsOnID, &dep.Type, &createdAt, &dep.CreatedBy, &metadata, &threadID); err != nil {\n\t\treturn nil, fmt.Errorf(\"scan dependency: %w\", err)\n\t}\n\n\tif createdAt.Valid {\n\t\tdep.CreatedAt = createdAt.Time\n\t}\n\tif metadata.Valid {\n\t\tdep.Metadata = metadata.String\n\t}\n\tif threadID.Valid {\n\t\tdep.ThreadID = threadID.String\n\t}\n\n\treturn &dep, nil\n}\n","sourceCodeStart":1048,"sourceCodeEnd":1081,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/dependency_queries.go#L1048-L1081","documentation":"scanDependencyRow converts one dependency row into types.Dependency; this error wraps a Scan failure of (issue_id, depends_on_id, type, created_at, created_by, metadata, thread_id). It fires when the dependencies table row shape differs from the expected seven columns or a column type can't convert (NULL in a non-nullable-scanned column, wrong type). Callers getDependencyRecordsIntoFromTable / getAllDependencyRecordsIntoFromTable propagate it.","triggerScenarios":"Reading dependency records when the dependencies table schema changed (columns added/removed/reordered) or a column that must be non-NULL (issue_id, depends_on_id, type) is NULL; metadata/thread_id NULLability is handled via sql.NullString, so the failure usually comes from the first three columns or created_at type drift.","commonSituations":"Version mismatch between beads binary and database schema; manual ALTERs to the dependencies table; corrupted rows where required columns are NULL after a failed import.","solutions":["Run `bd doctor` / migrations to restore the expected dependencies schema.","Find and repair offending rows (SELECT rows with NULL issue_id/depends_on_id/type) and delete or fix them.","Re-sync the database (bd dolt pull / re-import) if rows are corrupt.","Match the binary version to the schema version that created the database."],"exampleFix":"// before: schema has 8 columns, Scan expects 7 -> mismatch\nif err := rows.Scan(&dep.IssueID, &dep.DependsOnID, &dep.Type, &createdAt, &dep.CreatedBy, &metadata, &threadID); err != nil {\n\treturn nil, fmt.Errorf(\"scan dependency: %w\", err)\n}\n// after: migrate DB back to expected shape, or widen Scan if a new column is intentional\nvar extra sql.NullString\nif err := rows.Scan(&dep.IssueID, &dep.DependsOnID, &dep.Type, &createdAt, &dep.CreatedBy, &metadata, &threadID, &extra); err != nil {\n\treturn nil, fmt.Errorf(\"scan dependency: %w\", err)\n}","handlingStrategy":"validation","validationCode":"cols, err := dependencyTableColumns(db)\nif err != nil { return err }\nwant := []string{\"issue_id\", \"depends_on_id\", \"type\", \"created_at\", \"created_by\", \"metadata\", \"thread_id\"}\nif !equalCols(cols, want) {\n\treturn fmt.Errorf(\"dependencies schema drift: got %v want %v\", cols, want)\n}","typeGuard":"func isSchemaMismatchErr(err error) bool {\n\tmsg := err.Error()\n\treturn strings.Contains(msg, \"sql: expected \") ||\n\t\tstrings.Contains(msg, \"Unknown column\") ||\n\t\tstrings.Contains(msg, \"convert\")\n}","tryCatchPattern":"deps, err := getAllDependencyRecordsIntoFromTable(ctx, tx, dest, table)\nif err != nil {\n\tif isSchemaMismatchErr(err) {\n\t\treturn fmt.Errorf(\"run `bd doctor`/migrations: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Migrate the database before upgrading the beads binary.","Run `bd doctor` after version changes to catch schema drift.","Repair or remove rows with NULL in required dependency columns.","Keep the dependencies table schema owned by beads migrations only."],"tags":["sql","scan-error","storage","dependencies"],"backgroundTag":"sql-rows-scan-type-mismatch","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}