gastownhall/beads · error

db: DependencySQLRepository.GetTree: %w

Error message

db: DependencySQLRepository.GetTree: %w

What it means

GetTree calls issueops.GetDependencyTreeInTx with the root ID, a maxDepth (defaulting to 50), ShowAllPaths, and direction-derived reverse flag. This wrapper means the underlying tree-walk query failed. Note that within a transaction this walk runs unwrapped internally; this error surfaces only when the in-tx implementation itself returns an error.

Source

Thrown at internal/storage/domain/db/dependency.go:933

func (r *dependencySQLRepositoryImpl) CountEdges(ctx context.Context, req publicops.EdgeCountRequest) (publicops.EdgeCountResult, error) {
	return issueops.ExecuteEdgeCount(ctx, r.runner, req)
}

func (r *dependencySQLRepositoryImpl) GetTree(ctx context.Context, rootID string, opts domain.DepTreeOpts) ([]*types.TreeNode, error) {
	if rootID == "" {
		return nil, errors.New("db: DependencySQLRepository.GetTree: rootID must not be empty")
	}
	if opts.Direction == domain.DepDirectionBoth {
		return nil, errors.New("db: DependencySQLRepository.GetTree: DepDirectionBoth not supported; callers must invoke once per direction and merge")
	}
	maxDepth := opts.MaxDepth
	if maxDepth <= 0 {
		maxDepth = 50
	}
	reverse := opts.Direction == domain.DepDirectionIn
	out, err := issueops.GetDependencyTreeInTx(ctx, r.runner, rootID, maxDepth, opts.ShowAllPaths, reverse)
	if err != nil {
		return nil, fmt.Errorf("db: DependencySQLRepository.GetTree: %w", err)
	}
	return out, nil
}

func (r *dependencySQLRepositoryImpl) CycleThroughEdges(ctx context.Context, edges [][2]string) (string, error) {
	if len(edges) == 0 {
		return "", nil
	}
	graph := make(map[string][]string)
	if err := issueops.AppendSchedulingGraphInTx(ctx, r.runner, []string{"dependencies"}, graph); err != nil {
		return "", fmt.Errorf("db: DependencySQLRepository.CycleThroughEdges: %w", err)
	}
	if err := issueops.AppendSchedulingGraphInTx(ctx, r.runner, []string{"wisp_dependencies"}, graph); err != nil && !dberrors.IsTableNotExist(err) {
		return "", fmt.Errorf("db: DependencySQLRepository.CycleThroughEdges (wisps): %w", err)
	}
	return issueops.CycleThroughEdgesInGraph(graph, edges), nil
}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Unwrap to find the root SQL/driver error.
  2. Reduce maxDepth or set ShowAllPaths=false if the walk times out on large trees.
  3. Verify schema and connectivity; retry transient failures.
  4. Confirm the root ID belongs to an existing issue.

Example fix

// before
tree, err := repo.GetTree(ctx, rootID, 0, opts) // deep tree, default 50 depth
// after: cap depth for large graphs
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
tree, err := repo.GetTree(ctx, rootID, 10, opts)
Defensive patterns

Strategy: validation

Validate before calling

if rootID == "" {
    return errors.New("GetTree requires a non-empty root issue ID")
}
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()

Type guard

func validTreeRequest(rootID string, maxDepth int) bool {
    return rootID != "" && (maxDepth > 0 || maxDepth == 0) // 0 => default 50
}

Try / catch

tree, err := repo.GetTree(ctx, rootID, maxDepth, opts)
if err != nil {
    if errors.Is(err, context.DeadlineExceeded) {
        return repo.GetTree(ctx, rootID, 10, opts) // shallower retry
    }
    return fmt.Errorf("dep tree %s: %w", rootID, err)
}

Prevention

When it happens

Trigger: Calling GetTree(ctx, rootID, maxDepth, opts) when GetDependencyTreeInTx errors: SQL failure traversing dependencies, connection loss, context cancellation, or excessive recursion/depth query errors.

Common situations: Traversing from a root in a corrupted or partially migrated database; context timeout while walking a deep tree; database restarted mid-walk.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/3edc71ad3ea1d545. Report an issue: GitHub.