{"record":{"id":"ef7f0a629bde10cb","repo":"gastownhall/beads","slug":"failed-to-check-dependency-target-s-for-s-w","errorCode":null,"errorMessage":"failed to check dependency target %s for %s: %w","messagePattern":"failed to check dependency target (.+?) for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/create.go","lineNumber":911,"sourceCode":"\t\t\t}\n\t\t\tisCrossPrefix := types.ExtractPrefix(dep.IssueID) != types.ExtractPrefix(dep.DependsOnID)\n\t\t\tkind := ClassifyDepTarget(ctx, tx, dep, isCrossPrefix)\n\n\t\t\tif kind != DepTargetExternal {\n\t\t\t\tlookupTable := \"issues\"\n\t\t\t\tif kind == DepTargetWisp {\n\t\t\t\t\tlookupTable = \"wisps\"\n\t\t\t\t}\n\t\t\t\tvar exists int\n\t\t\t\t//nolint:gosec // G201: lookupTable is one of two hardcoded constants\n\t\t\t\tif err := tx.QueryRowContext(ctx,\n\t\t\t\t\tfmt.Sprintf(\"SELECT 1 FROM %s WHERE id = ?\", lookupTable),\n\t\t\t\t\tdep.DependsOnID).Scan(&exists); err != nil {\n\t\t\t\t\tif err == sql.ErrNoRows {\n\t\t\t\t\t\trecordSkippedDependency(opts, dep, \"target not found\")\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\treturn result, fmt.Errorf(\"failed to check dependency target %s for %s: %w\", dep.DependsOnID, dep.IssueID, err)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif kind != DepTargetExternal && types.ExtractPrefix(dep.IssueID) == types.ExtractPrefix(dep.DependsOnID) {\n\t\t\t\tif err := CheckBlockingHierarchyInTx(ctx, tx, dep, nil); err != nil {\n\t\t\t\t\tif opts.SkipDependencyValidationErrors {\n\t\t\t\t\t\trecordSkippedDependency(opts, dep, err.Error())\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\treturn result, fmt.Errorf(\"invalid dependency %s -> %s: %w\", dep.IssueID, dep.DependsOnID, err)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif err := CheckDependencyCycleInTx(ctx, tx, dep, nil); err != nil {\n\t\t\t\tif opts.SkipDependencyValidationErrors {\n\t\t\t\t\trecordSkippedDependency(opts, dep, err.Error())\n\t\t\t\t\tcontinue\n\t\t\t\t}","sourceCodeStart":893,"sourceCodeEnd":929,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/create.go#L893-L929","documentation":"PersistDependenciesWithOptionsResult validates each dependency's target: for non-external targets it looks up DependsOnID in the lookup table. If the lookup query fails (anything other than sql.ErrNoRows, which is handled as 'target not found' and skipped), the error is wrapped as 'failed to check dependency target <target> for <issue>'. This is a query-failure path, distinct from the handled missing-target case.","triggerScenarios":"Creating issues with dependencies via CreateIssuesInTxWithContext / PersistDependenciesWithResult when the SELECT 1 FROM <lookupTable> WHERE id = ? query errors — missing/corrupt lookup table, connection failure, cancelled context, or malformed SQL due to table-name drift.","commonSituations":"Bulk import against a half-migrated schema; remote Dolt server connection dropping mid-import; context cancellation during long dependency validation; running tests/importers against an uninitialized database.","solutions":["Inspect the wrapped %w error for the SQL root cause (no such table, connection refused, ctx cancelled) and fix it.","Run schema initialization/migrations so the issues lookup table exists before importing dependencies.","Retry the import after connectivity is restored; use SetSkipDependencyValidationErrors only for soft validation errors, not query failures.","Increase the context budget or split the import into smaller batches so validation completes within the deadline."],"exampleFix":"// before\nctx, cancel := context.WithTimeout(ctx, 1*time.Second)\ndefer cancel()\nresult, err := issueops.PersistDependenciesWithResult(ctx, tx, deps, opts) // ctx cancelled mid-lookup\n// after\nctx, cancel := context.WithTimeout(ctx, 60*time.Second)\ndefer cancel()\nresult, err := issueops.PersistDependenciesWithResult(ctx, tx, deps, opts)","handlingStrategy":"validation","validationCode":"// pre-verify dependency targets exist before persisting\nfor _, dep := range deps {\n    var n int\n    if err := tx.QueryRowContext(ctx,\n        \"SELECT COUNT(*) FROM issues WHERE id = ?\", dep.DependsOnID).Scan(&n); err != nil {\n        return err\n    }\n    if n == 0 { return fmt.Errorf(\"missing dependency target %s\", dep.DependsOnID) }\n}","typeGuard":null,"tryCatchPattern":"result, err := issueops.PersistDependenciesWithResult(ctx, tx, deps, opts)\nif err != nil && strings.Contains(err.Error(), \"failed to check dependency target\") {\n    if isTransient(err) {\n        return retryWithBackoff(ctx, func() error {\n            _, e := issueops.PersistDependenciesWithResult(ctx, tx, deps, opts)\n            return e\n        })\n    }\n    return err\n}","preventionTips":["Complete schema migrations before importing dependency edges.","Import issues before their dependencies so targets exist.","Use generous context deadlines; split very large dependency batches.","Reserve SkipDependencyValidationErrors for validation problems, not query failures."],"tags":["storage","dependencies","database"],"backgroundTag":"dependency-lookup-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}