{"record":{"id":"7ddf12107bcbfcbf","repo":"gastownhall/beads","slug":"get-dependency-counts-dependents-from-s-w","errorCode":null,"errorMessage":"get dependency counts (dependents from %s): %w","messagePattern":"get dependency counts \\(dependents from (.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/dependency_queries.go","lineNumber":503,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t\t_ = depRows.Close()\n\t\t\tif err := depRows.Err(); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"get dependency counts: blocker rows: %w\", err)\n\t\t\t}\n\n\t\t\t//nolint:gosec // G201: depTable is hardcoded and inClause contains only ? placeholders.\n\t\t\tblockingRows, err := tx.QueryContext(ctx, fmt.Sprintf(`\n\t\t\t\tSELECT %s AS depends_on_id, COUNT(*) as cnt\n\t\t\t\tFROM %s\n\t\t\t\tWHERE %s AND type = 'blocks'\n\t\t\t\tGROUP BY %s\n\t\t\t`, DepTargetExpr, depTable, depTargetIn(\"\", inClause), DepTargetExpr), args...)\n\t\t\tif err != nil {\n\t\t\t\tif optionalBlockedTable(depTable) && isTableNotExistError(err) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"get dependency counts (dependents from %s): %w\", depTable, err)\n\t\t\t}\n\t\t\tfor blockingRows.Next() {\n\t\t\t\tvar id string\n\t\t\t\tvar cnt int\n\t\t\t\tif err := blockingRows.Scan(&id, &cnt); err != nil {\n\t\t\t\t\t_ = blockingRows.Close()\n\t\t\t\t\treturn nil, fmt.Errorf(\"get dependency counts: scan dependent: %w\", err)\n\t\t\t\t}\n\t\t\t\tif c, ok := result[id]; ok {\n\t\t\t\t\tc.DependentCount += cnt\n\t\t\t\t}\n\t\t\t}\n\t\t\t_ = blockingRows.Close()\n\t\t\tif err := blockingRows.Err(); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"get dependency counts: dependent rows: %w\", err)\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/dependency_queries.go#L485-L521","documentation":"Returned by GetDependencyCountsInTx when the 'dependents' aggregate query (SELECT depends_on_id, COUNT(*) FROM <depTable> WHERE depends_on_id IN (...) AND type='blocks' GROUP BY depends_on_id) fails at QueryContext time and the failure is not a tolerated missing optional table. The %s names which dependency table (dependencies or wisp_dependencies) failed; %w wraps the driver error (syntax, connection, permissions, etc.).","triggerScenarios":"Calling GetDependencyCountsInTx when the dependencies table is missing entirely (fresh/corrupt DB — the optional-table skip only applies to wisp_dependencies), the SQL text fails to compile against the backend, the connection is broken, or the user lacks SELECT permission on the table.","commonSituations":"Database created before the dependencies table existed and never migrated; restricted DB user without SELECT grants; incompatible Dolt server rejecting the query dialect; corrupted database file.","solutions":["Inspect the wrapped driver error to identify whether it is no-such-table, permission denied, or connection failure.","If the table is missing, initialize/migrate the database (bd init / schema migration) so the dependencies table exists.","If permission denied, grant SELECT on dependencies/wisp_dependencies to the DB user.","If it is a connection error, verify the remote Dolt server is reachable and the connection string is correct.","Check client/server version compatibility if the SQL dialect is rejected."],"exampleFix":"// before: DB user without SELECT grants\nCREATE USER 'bd'@'%' IDENTIFIED BY '...';\n\n// after: grant required read access\nGRANT SELECT ON beads.* TO 'bd'@'%';\nFLUSH PRIVILEGES;","handlingStrategy":"validation","validationCode":"// Go: ensure required tables exist before calling\nvar n int\nif err := tx.QueryRowContext(ctx,\n    \"SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_NAME IN ('dependencies','issues')\").Scan(&n); err != nil {\n    return err\n}\nif n < 2 {\n    return fmt.Errorf(\"required tables missing; run bd migrate\")\n}","typeGuard":"func isMissingTable(err error) bool {\n    return err != nil && (strings.Contains(err.Error(), \"no such table\") ||\n        strings.Contains(err.Error(), \"doesn't exist\"))\n}","tryCatchPattern":"counts, err := GetDependencyCountsInTx(ctx, tx, ids)\nif err != nil && strings.Contains(err.Error(), \"dependents from dependencies\") {\n    if isMissingTable(errors.Unwrap(err)) {\n        return fmt.Errorf(\"database not initialized: run bd migrate\")\n    }\n    return err\n}","preventionTips":["Run migrations after every binary upgrade before touching data.","Verify DB grants include SELECT on all beads tables.","Confirm remote server reachability with a cheap SELECT 1 probe.","Keep client and Dolt server versions aligned."],"tags":["database","sql","query-failed","schema"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}