{"record":{"id":"ab56eda31a84a0e6","repo":"gastownhall/beads","slug":"create-add-dep-s-s-w","errorCode":null,"errorMessage":"create: add dep %s -> %s: %w","messagePattern":"create: add dep (.+?) -> (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/issue.go","lineNumber":1042,"sourceCode":"\t}\n\n\tfor _, spec := range params.Dependencies {\n\t\tdep := &types.Dependency{\n\t\t\tIssueID:     issue.ID,\n\t\t\tDependsOnID: spec.TargetID,\n\t\t\tType:        spec.Type,\n\t\t\tMetadata:    spec.Metadata,\n\t\t\tThreadID:    spec.ThreadID,\n\t\t}\n\t\tif spec.SwapDirection {\n\t\t\tdep.IssueID, dep.DependsOnID = dep.DependsOnID, dep.IssueID\n\t\t}\n\t\tdepSourceIsWisp, err := u.isWispID(ctx, dep.IssueID)\n\t\tif err != nil {\n\t\t\treturn result, fmt.Errorf(\"create: determine dep source tier for %s: %w\", dep.IssueID, err)\n\t\t}\n\t\tif err := u.depRepo.Insert(ctx, dep, actor, DepInsertOpts{UseWispsTable: depSourceIsWisp}); err != nil {\n\t\t\treturn result, fmt.Errorf(\"create: add dep %s -> %s: %w\", dep.IssueID, dep.DependsOnID, err)\n\t\t}\n\t\tresult.PostCreateWrites = true\n\t}\n\n\tif params.WaitsFor != nil {\n\t\t// Spawner identity is the depends_on_id; metadata carries the gate.\n\t\tdep, err := types.NewWaitsForDependency(issue.ID, params.WaitsFor.SpawnerID, params.WaitsFor.Gate)\n\t\tif err != nil {\n\t\t\treturn result, fmt.Errorf(\"create: marshal waits-for meta: %w\", err)\n\t\t}\n\t\tif err := u.depRepo.Insert(ctx, dep, actor, DepInsertOpts{UseWispsTable: useWisp}); err != nil {\n\t\t\treturn result, fmt.Errorf(\"create: add waits-for: %w\", err)\n\t\t}\n\t\tresult.PostCreateWrites = true\n\t}\n\n\treturn result, nil\n}","sourceCodeStart":1024,"sourceCodeEnd":1060,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/issue.go#L1024-L1060","documentation":"Wraps a failure from depRepo.Insert while adding a dependency (issue depends on another issue) during issue creation inside the storage domain use case. The underlying insert can fail for schema/constraint reasons (unknown issue ID, FK violation, cycle checks) or storage-layer errors. The wrapper names the dependency edge 'issueID -> dependsOnID' so the failing relationship is identifiable.","triggerScenarios":"Calling Create/CreateIssues with Dependencies (or a graph plan) where dep.IssueID or dep.DependsOnID does not resolve to an inserted issue, the deps table insert violates a constraint, or the underlying DB/driver fails during Insert.","commonSituations":"Creating issues with dependencies on IDs that were never created or were deleted; typo'd issue IDs in a dependency list; DB constraint changes after schema migration; transient Dolt/storage failures during batch create.","solutions":["Verify both dep.IssueID and dep.DependsOnID exist (create referenced issues first, or use graph apply which mints IDs before linking)","Check the wrapped inner error (%w) for the storage-level cause (FK violation, duplicate, connection)","Confirm the correct table tier: wisps deps go to the wisps table via UseWispsTable; a wisp ID routed wrong can fail lookup","Retry transient storage errors; investigate driver/connection if persistent"],"exampleFix":"// before: dep references an issue that doesn't exist yet\nCreateIssueParams{Issue: child, Dependencies: []Dependency{{IssueID: child.ID, DependsOnID: \"bd-999\"}}}\n// after: create the parent first, then reference its real ID\nparent, _ := uc.Create(ctx, parentParams, actor)\nCreateIssueParams{Issue: child, Dependencies: []Dependency{{IssueID: child.ID, DependsOnID: parent.ID}}}","handlingStrategy":"validation","validationCode":"for _, dep := range params.Dependencies {\n    if dep.IssueID == \"\" || dep.DependsOnID == \"\" {\n        return fmt.Errorf(\"dependency has empty endpoint: %+v\", dep)\n    }\n    if _, err := uc.GetIssue(ctx, dep.DependsOnID); err != nil {\n        return fmt.Errorf(\"dep target %s does not exist\", dep.DependsOnID)\n    }\n}","typeGuard":null,"tryCatchPattern":"var result CreateIssuesResult\nresult, err := uc.CreateIssues(ctx, params, actor)\nif err != nil {\n    var idxErr string\n    if strings.Contains(err.Error(), \"create: add dep \") {\n        // parse edge from message and inspect wrapped cause\n        idxErr = err.Error()\n    }\n    return fmt.Errorf(\"dependency insert failed: %v\", idxErr)\n}","preventionTips":["Create referenced issues before adding dependencies to them","Validate dependency endpoints are non-empty and well-formed","Prefer graph apply for interlinked issues so IDs are minted before edges","Check wisp vs durable tier consistency for both endpoints"],"tags":["storage","dependency-insert","go","database"],"backgroundTag":"dependency-insert-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}