{"record":{"id":"46f3ba8fc3cad712","repo":"gastownhall/beads","slug":"get-all-dependency-records-from-s-w","errorCode":null,"errorMessage":"get all dependency records from %s: %w","messagePattern":"get all dependency records from (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/dependency_queries.go","lineNumber":41,"sourceCode":"\t\t\treturn nil, err\n\t\t}\n\t}\n\treturn result, nil\n}\n\n//nolint:gosec // G201: depTable is \"dependencies\" or \"wisp_dependencies\" (hardcoded by caller).\nfunc getAllDependencyRecordsIntoFromTable(ctx context.Context, tx DBTX, depTable string, result map[string][]*types.Dependency) error {\n\t// Total order: issue_id alone is only a grouping key; without a tiebreaker the\n\t// intra-issue dependency slice is plan-dependent (export churn, unstable --json).\n\t// Mirrors labels bulk-load (issue_id, label). The separate typed-target unique\n\t// keys don't make (issue_id, depends_on_id, type) total, so `id` closes it.\n\trows, err := tx.QueryContext(ctx, fmt.Sprintf(`\n\t\t\tSELECT issue_id, %s AS depends_on_id, type, created_at, created_by, metadata, thread_id\n\t\t\tFROM %s\n\t\t\tORDER BY issue_id, depends_on_id, type, id\n\t\t`, DepTargetExpr, depTable))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get all dependency records from %s: %w\", depTable, err)\n\t}\n\tdefer rows.Close()\n\n\tfor rows.Next() {\n\t\tdep, scanErr := scanDependencyRow(rows)\n\t\tif scanErr != nil {\n\t\t\treturn fmt.Errorf(\"get all dependency records from %s: %w\", depTable, scanErr)\n\t\t}\n\t\tresult[dep.IssueID] = append(result[dep.IssueID], dep)\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn fmt.Errorf(\"get all dependency records from %s: %w\", depTable, err)\n\t}\n\treturn nil\n}\n\n// GetDependencyRecordsForIssuesInTx returns dependency records for specific issues,\n// routing each ID to dependencies or wisp_dependencies based on wisp status.","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/dependency_queries.go#L23-L59","documentation":"getAllDependencyRecordsIntoFromTable wraps the error from tx.QueryContext when loading every dependency record from a given table (issues_dependencies or wisp_dependencies, chosen by depTable). The message includes the table name and the underlying driver error via %w, so callers can tell which table's full scan failed and why. GetAllDependencyRecordsInTx fans out to this for each dependency table.","triggerScenarios":"tx.QueryContext failing inside GetAllDependencyRecordsInTx — e.g. connection loss mid-transaction, an SQL syntax/permission problem from the interpolated DepTargetExpr/depTable, or a driver error while issuing the SELECT over all dependency rows.","commonSituations":"Server restarted or connection dropped during a long export/sync; schema mismatch after a version upgrade where the expected dependency table or columns are missing; running against a database user lacking SELECT privileges.","solutions":["Unwrap the %w cause with errors.As to identify the driver error (connection, syntax, privilege) and fix that root cause.","Retry the containing transaction; the query is read-only within it so a fresh transaction is safe.","After a version upgrade, verify the schema has the expected dependency tables and columns (the driver owns schema; do not patch around it).","Check the database user's SELECT grants on both dependency tables."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"deps, err := GetAllDependencyRecordsInTx(ctx, tx)\nif err != nil {\n    var drv driver.Error\n    if errors.As(err, &drv) {\n        // inspect wrapped driver error (connection/privilege/syntax)\n    }\n    return fmt.Errorf(\"load dependencies: %w\", err)\n}","preventionTips":["Run exports/syncs inside retry-wrapped transactions so transient driver errors are absorbed.","After upgrades, confirm the schema (driver-owned) still matches the expected dependency tables/columns.","Ensure the DB user has SELECT on both dependency tables.","Monitor connection health for long-running full-table reads."],"tags":["go","database","sql","query-failed"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}