{"record":{"id":"fa6d6ac983172591","repo":"gastownhall/beads","slug":"db-dependencysqlrepository-delete-s-s-w","errorCode":null,"errorMessage":"db: DependencySQLRepository.Delete: %s -> %s: %w","messagePattern":"db: DependencySQLRepository\\.Delete: (.+?) -> (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/dependency.go","lineNumber":354,"sourceCode":"\tvar depType, depMetadata string\n\t//nolint:gosec // G201: table and depTargetExpr are hardcoded constants\n\terr := r.runner.QueryRowContext(ctx,\n\t\tfmt.Sprintf(\"SELECT type, metadata FROM %s WHERE issue_id = ? AND %s = ?\", table, depTargetExpr),\n\t\tissueID, dependsOnID,\n\t).Scan(&depType, &depMetadata)\n\tswitch {\n\tcase errors.Is(err, sql.ErrNoRows):\n\t\treturn domain.DepDeleteResult{Found: false}, nil\n\tcase err != nil:\n\t\treturn domain.DepDeleteResult{}, fmt.Errorf(\"db: DependencySQLRepository.Delete: lookup type %s -> %s: %w\", issueID, dependsOnID, err)\n\t}\n\n\t//nolint:gosec // G201: table and depTargetExpr are hardcoded constants\n\tif _, err := r.runner.ExecContext(ctx,\n\t\tfmt.Sprintf(\"DELETE FROM %s WHERE issue_id = ? AND %s = ?\", table, depTargetExpr),\n\t\tissueID, dependsOnID,\n\t); err != nil {\n\t\treturn domain.DepDeleteResult{}, fmt.Errorf(\"db: DependencySQLRepository.Delete: %s -> %s: %w\", issueID, dependsOnID, err)\n\t}\n\n\t// The type lookup above returned Found:false when no edge existed, so reaching\n\t// here means a row was deleted — record the dependency_removed event on the\n\t// source's event table, matching the embedded/issueops RemoveDependencyInTx path.\n\t// Gated on EmitEvent so only the explicit `bd dep remove` verb emits.\n\tif opts.EmitEvent {\n\t\tif err := r.events.Record(ctx, domain.Event{\n\t\t\tIssueID:  issueID,\n\t\t\tType:     types.EventDependencyRemoved,\n\t\t\tActor:    actor,\n\t\t\tNewValue: fmt.Sprintf(\"Removed dependency on %s\", dependsOnID),\n\t\t}, domain.RecordEventOpts{UseWispsTable: opts.UseWispsTable}); err != nil {\n\t\t\treturn domain.DepDeleteResult{}, fmt.Errorf(\"db: DependencySQLRepository.Delete: record dependency_removed event: %w\", err)\n\t\t}\n\t}\n\n\tdt := types.DependencyType(depType)","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/dependency.go#L336-L372","documentation":"This error wraps the driver error from the DELETE statement removing the dependency edge row. The type lookup confirmed the edge existed, but the actual DELETE FROM <table> WHERE issue_id = ? AND <target> = ? failed.","triggerScenarios":"Calling Delete on an existing edge where ExecContext fails — foreign-key restriction from child rows, connection loss, read-only backend, or lock contention.","commonSituations":"Row locked by a concurrent transaction; database on a read-only replica; driver-level FK restrictions; storage quota/connection issues.","solutions":["Retry after checking for lock contention (another bd process or sync holding the row).","Verify the database is writable (not a read-only replica).","Check connectivity and re-run; Delete is safe to retry since it re-looks-up the edge.","Inspect the wrapped driver error for the specific SQL failure."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// confirm edge exists and DB is writable before Delete\nvar depType string\nif err := db.QueryRow(\"SELECT type FROM dependencies WHERE issue_id=? AND depends_on_id=?\", issueID, dependsOnID).Scan(&depType); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"res, err := repo.Delete(ctx, issueID, dependsOnID)\nif err != nil {\n    if strings.Contains(err.Error(), \"Delete:\") {\n        // DELETE failed: check locks/read-only state, retry safely (lookup re-runs)\n    }\n}\nif res != nil && !res.Found { /* edge absent */ }","preventionTips":["Avoid concurrent writers on the same edge; serialize deletes.","Point bd at a writable primary.","Retry deletes on transient failure — they re-verify existence first."],"tags":["database","sql","delete-failed","dependency-delete"],"backgroundTag":"dependency-delete-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}