{"record":{"id":"93da2c4634875367","repo":"gastownhall/beads","slug":"db-dependencysqlrepository-delete-lookup-type-s","errorCode":null,"errorMessage":"db: DependencySQLRepository.Delete: lookup type %s -> %s: %w","messagePattern":"db: DependencySQLRepository\\.Delete: lookup type (.+?) -> (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/dependency.go","lineNumber":346,"sourceCode":"}\n\nfunc (r *dependencySQLRepositoryImpl) Delete(ctx context.Context, issueID, dependsOnID, actor string, opts domain.DepInsertOpts) (domain.DepDeleteResult, error) {\n\tif issueID == \"\" || dependsOnID == \"\" {\n\t\treturn domain.DepDeleteResult{}, errors.New(\"db: DependencySQLRepository.Delete: issueID and dependsOnID must not be empty\")\n\t}\n\ttable := pickDepTable(opts.UseWispsTable)\n\n\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,","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/dependency.go#L328-L364","documentation":"This error wraps a failure from the type-lookup SELECT at the start of DependencySQLRepository.Delete, which reads the existing edge's type and metadata before deleting. A missing edge is handled gracefully (Found:false); this error means the lookup query itself failed.","triggerScenarios":"Calling Delete(issueID, dependsOnID) where the SELECT type/metadata for the edge fails with a driver error other than ErrNoRows — connection failure, missing table, permission denied.","commonSituations":"Database unavailable or mid-migration; wrong table due to wisp vs issue plane confusion; revoked SELECT privileges.","solutions":["Check DB connectivity and retry.","Verify the dependencies/wisp_dependencies tables exist in the current schema.","Confirm you are targeting the correct storage plane (issues vs wisps).","Inspect the wrapped driver error for the underlying cause."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-check the edge exists before Delete\nvar depType string\nerr := db.QueryRow(\"SELECT type FROM dependencies WHERE issue_id=? AND depends_on_id=?\", issueID, dependsOnID).Scan(&depType)\nif errors.Is(err, sql.ErrNoRows) {\n    return // nothing to delete\n}","typeGuard":null,"tryCatchPattern":"res, err := repo.Delete(ctx, issueID, dependsOnID)\nif err != nil {\n    if strings.Contains(err.Error(), \"lookup type\") {\n        // lookup failed: check connectivity/table existence, retry\n    }\n}","preventionTips":["Confirm DB connectivity before delete batches.","Keep dependencies tables migrated.","Use the correct plane (wisps vs issues) for the edge."],"tags":["database","sql","dependency-delete","lookup-failed"],"backgroundTag":"dependency-lookup-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}