{"record":{"id":"5b7996d33bbd8dd4","repo":"gastownhall/beads","slug":"add-deps-d-insert-w","errorCode":null,"errorMessage":"add deps[%d]: insert: %w","messagePattern":"add deps\\[(.+?)\\]: insert: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/dependency.go","lineNumber":762,"sourceCode":"\t\t\t// create-with-deps, which calls depRepo.Insert directly without\n\t\t\t// EmitEvent. UseWispsTable routes both the edge and that event to\n\t\t\t// the source's own pair of tables.\n\t\t\t_, sourceIsWisp := wispSources[dep.IssueID]\n\t\t\tif err := u.depRepo.Insert(ctx, dep, actor, DepInsertOpts{\n\t\t\t\tUseWispsTable:      sourceIsWisp,\n\t\t\t\tHierarchyValidated: true,\n\t\t\t\tCycleValidated:     true,\n\t\t\t\tEmitEvent:          true,\n\t\t\t}); err != nil {\n\t\t\t\tvar hierarchyConflict *DependencyHierarchyConflictError\n\t\t\t\tif errors.As(err, &hierarchyConflict) {\n\t\t\t\t\treturn BulkAddDepsResult{}, err\n\t\t\t\t}\n\t\t\t\tvar missingEndpoint *DependencyEndpointNotFoundError\n\t\t\t\tif errors.As(err, &missingEndpoint) {\n\t\t\t\t\treturn BulkAddDepsResult{}, err\n\t\t\t\t}\n\t\t\t\treturn BulkAddDepsResult{}, fmt.Errorf(\"add deps[%d]: insert: %w\", i, err)\n\t\t\t}\n\t\t}\n\t}\n\tvar pairs [][2]string\n\tfor _, dep := range deps {\n\t\tif !types.IsSchedulingEdge(dep.Type) {\n\t\t\tcontinue\n\t\t}\n\t\tpairs = append(pairs, [2]string{dep.IssueID, dep.DependsOnID})\n\t}\n\tif len(pairs) > 0 {\n\t\tcyclePath, err := u.depRepo.CycleThroughEdges(ctx, pairs)\n\t\tif err != nil {\n\t\t\treturn BulkAddDepsResult{}, fmt.Errorf(\"add deps: final cycle check: %w\", err)\n\t\t}\n\t\tif cyclePath != \"\" {\n\t\t\treturn BulkAddDepsResult{}, cycleErrorf(\"add deps: dependency cycle would be created: %s\", cyclePath)\n\t\t}","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/dependency.go#L744-L780","documentation":"When inserting an individual dependency edge fails, AddDependencies wraps it with 'insert: %w'. Typed failures — *DependencyHierarchyConflictError and *DependencyEndpointNotFoundError — are returned unwrapped so callers can errors.As them; everything else (e.g. constraint violations, storage errors) gets this wrapper. It means the edge write itself was rejected or failed.","triggerScenarios":"Calling AddDependencies where the per-edge repository insert returns a non-typed error — duplicate-edge constraint violations, storage write failures, or other driver errors not classified as hierarchy-conflict or missing-endpoint.","commonSituations":"Concurrent writers inserting the same edge; database read-only or disk full; referential issues when one endpoint was deleted between validation and insert.","solutions":["Read the wrapped error after 'insert:' for the driver-level cause","Re-check that both endpoint issues still exist before retrying","If duplicates are expected, filter existing edges before the batch or tolerate the error per-edge"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure both endpoints exist before the call\nfor _, d := range deps {\n    if _, err := issueRepo.Get(ctx, d.IssueID); err != nil { return err }\n    if _, err := issueRepo.Get(ctx, d.DependsOnID); err != nil { return err }\n}","typeGuard":"var miss *domain.DependencyEndpointNotFoundError\nif errors.As(err, &miss) { /* handle missing endpoint typed path */ }","tryCatchPattern":"if err != nil {\n    var hc *domain.DependencyHierarchyConflictError\n    var me *domain.DependencyEndpointNotFoundError\n    if errors.As(err, &hc) || errors.As(err, &me) { return err } // typed, unwrapped\n    // 'insert:' wrapper — driver/constraint issue; inspect wrapped cause\n}","preventionTips":["Serialize concurrent writers that may insert the same edge","Ensure endpoints exist and were not deleted mid-batch","Check disk space / read-only filesystem before large writes"],"tags":["dependencies","insert","database"],"backgroundTag":"dependency-insert-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}