gastownhall/beads · error

scan dependency target: %w

Error message

scan dependency target: %w

What it means

This error wraps a rows.Scan failure while loading a dependency-target row (nine columns including nullable targets, timestamps, and metadata) in replaceDependencyTargetInTx. It indicates a stored value whose type does not fit string/sql.NullString/sql.NullTime destinations — schema drift or corrupt row data.

Source

Thrown at internal/storage/issueops/dependencies.go:726

		metadata    sql.NullString
		threadID    sql.NullString
	}

	rows := make([]depRow, 0)
	//nolint:gosec // table and column are hardcoded by callers.
	queryRows, err := tx.QueryContext(ctx, fmt.Sprintf(`
		SELECT issue_id, depends_on_issue_id, depends_on_wisp_id, depends_on_external, type, created_at, created_by, metadata, thread_id
		FROM %s
		WHERE %s = ? OR (%s = ? AND depends_on_external IS NULL)
	`, table, column, DepTargetExpr), oldID, oldID)
	if err != nil {
		return fmt.Errorf("query dependency targets: %w", err)
	}
	for queryRows.Next() {
		var row depRow
		if err := queryRows.Scan(&row.issueID, &row.issueTarget, &row.wispTarget, &row.external, &row.depType, &row.createdAt, &row.createdBy, &row.metadata, &row.threadID); err != nil {
			_ = queryRows.Close()
			return fmt.Errorf("scan dependency target: %w", err)
		}
		switch column {
		case "depends_on_issue_id":
			row.issueTarget = sql.NullString{String: newID, Valid: true}
			row.wispTarget = sql.NullString{}
			row.external = sql.NullString{}
		case "depends_on_wisp_id":
			row.issueTarget = sql.NullString{}
			row.wispTarget = sql.NullString{String: newID, Valid: true}
			row.external = sql.NullString{}
		default:
			_ = queryRows.Close()
			return fmt.Errorf("replace dependency target: unsupported typed column %q", column)
		}
		rows = append(rows, row)
	}
	_ = queryRows.Close()
	if err := queryRows.Err(); err != nil {

View on GitHub (pinned to 71377f2769)

Solutions

  1. Read the wrapped Scan error to identify the mismatched column
  2. Run bd doctor / migrations to reconcile schema versions
  3. Inspect the row directly: SELECT * FROM <table> WHERE <target-column> = oldID
  4. Repair or restore the malformed row, then retry the rename

Example fix

// before: created_at holds '2026-08-30' as VARCHAR -> scan fails
scan dependency target: sql: Scan error on column index 5: unsupported Scan
// after: fix the column type/value
ALTER TABLE dependencies MODIFY created_at DATETIME NULL;
Defensive patterns

Strategy: validation

Validate before calling

// Find rows whose non-standard columns hold non-scan-friendly values
var bad int
db.Get(&bad, `SELECT COUNT(*) FROM dependencies
  WHERE (created_at IS NOT NULL AND NOT JSON_VALID(CAST(created_at AS CHAR)))
     OR type IS NULL OR type = ''`)
if bad > 0 { return fmt.Errorf("%d rows with malformed values; repair before renaming", bad) }

Prevention

When it happens

Trigger: UpdateIssueIDInTx / UpdateWispIDInTx rename, scanning a row from dependencies or wisp_dependencies whose type, created_at, created_by, metadata, or thread_id value cannot be scanned into its destination type.

Common situations: created_at stored as a non-time string after manual edits; rows written by an incompatible beads version; replication divergence in Dolt clones producing malformed values.

Related errors


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