{"record":{"id":"9bdaa84db4669120","repo":"gastownhall/beads","slug":"db-dependencysqlrepository-insert-w","errorCode":null,"errorMessage":"db: DependencySQLRepository.Insert: %w","messagePattern":"db: DependencySQLRepository\\.Insert: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/dependency.go","lineNumber":142,"sourceCode":"\t\t\t}\n\t\t\t// A same-type add refreshes edge metadata. It is an observable graph\n\t\t\t// mutation, so emit the complete replacement edge for replay.\n\t\t\treturn issueops.RecordDepEventInTx(ctx, r.runner, issueops.EventDepAdd, dep.IssueID, string(dep.Type), dep.DependsOnID, metadata, actor)\n\t\t}\n\t\treturn &domain.DependencyTypeConflictError{\n\t\t\tIssueID:       dep.IssueID,\n\t\t\tDependsOnID:   dep.DependsOnID,\n\t\t\tExistingType:  existingType,\n\t\t\tRequestedType: string(dep.Type),\n\t\t}\n\tcase errors.Is(err, sql.ErrNoRows):\n\tdefault:\n\t\treturn fmt.Errorf(\"db: DependencySQLRepository.Insert: check existing: %w\", err)\n\t}\n\n\ttargetCol, err := r.pickDepTargetColumn(ctx, dep.IssueID, dep.DependsOnID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"db: DependencySQLRepository.Insert: %w\", err)\n\t}\n\n\t// Deterministic id keyed on (issue_id, target), the same derivation as the\n\t// embedded/issueops path, so server-mode (use-case) dependency creation stays\n\t// merge-safe across clones and works once the DEFAULT (UUID()) is dropped (#4259).\n\t//nolint:gosec // G201: table is one of two hardcoded constants; targetCol is from pickDepTargetColumn\n\tif _, err := r.runner.ExecContext(ctx, fmt.Sprintf(`\n\t\tINSERT INTO %s (id, issue_id, %s, type, created_at, created_by, metadata, thread_id)\n\t\tVALUES (?, ?, ?, ?, ?, ?, ?, ?)\n\t`, table, targetCol),\n\t\tdepid.New(dep.IssueID, dep.DependsOnID), dep.IssueID, dep.DependsOnID, string(dep.Type),\n\t\ttime.Now().UTC(), actor, metadata, dep.ThreadID,\n\t); err != nil {\n\t\tif missing := r.classifyMissingEndpoint(ctx, dep, opts.UseWispsTable, targetCol, err); missing != nil {\n\t\t\treturn missing\n\t\t}\n\t\treturn fmt.Errorf(\"db: DependencySQLRepository.Insert: %w\", err)\n\t}","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/dependency.go#L124-L160","documentation":"This error wraps a failure from pickDepTargetColumn inside DependencySQLRepository.Insert. Before inserting a dependency edge, the repository probes the wisps table to classify the target as local issue, wisp, or external; if that probe query itself fails (not just returns no rows), the insert is aborted and the driver error is wrapped with this prefix.","triggerScenarios":"Calling Insert with a dependency whose target classification probe ('SELECT 1 FROM wisps WHERE id = ?') fails with a driver error other than ErrNoRows or table-not-exist — e.g. corrupted DB, connection failure, or permission error on the wisps table during the probe.","commonSituations":"Database connectivity dropped mid-transaction; wisps table locked or corrupted; running against a Dolt server with revoked SELECT privileges on wisps; transient network failure to the SQL backend.","solutions":["Check database connectivity and retry the operation (transient driver failures).","Verify the wisps table exists and the current user has SELECT permission on it.","Run bd doctor or a DB integrity check to rule out corruption.","Inspect the wrapped driver error (errors.Unwrap) for the underlying SQL cause."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// ensure the target id is non-empty and syntactically valid before Insert\nif dep.DependsOnID == \"\" || dep.IssueID == \"\" {\n    return fmt.Errorf(\"dependency endpoints must be non-empty\")\n}","typeGuard":null,"tryCatchPattern":"if err := repo.Insert(ctx, dep, actor, opts); err != nil {\n    if strings.Contains(err.Error(), \"classify dep target\") {\n        // DB probe failure: retry with backoff or check DB health\n    }\n}","preventionTips":["Keep the DB connection healthy (ping before bulk dep operations).","Ensure the schema is migrated so the wisps table exists.","Grant SELECT on wisps to the bd user.","Use bd doctor to catch corruption early."],"tags":["database","sql","dependency-insert"],"backgroundTag":"dependency-target-classification-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}