gastownhall/beads · error

get next child ID: scan child row: %w

Error message

get next child ID: scan child row: %w

What it means

While iterating child-ID rows, rows.Scan(&id) into a string failed and is wrapped as "get next child ID: scan child row: %w". Since the query selects only the id column (a string), this indicates a driver-level row conversion or connection problem rather than bad data shape.

Source

Thrown at internal/storage/issueops/child_id.go:40

	} else if err != nil {
		return "", fmt.Errorf("get next child ID: read counter: %w", err)
	}

	//nolint:gosec // G201: issueTable is one of two hardcoded constants.
	rows, err := tx.QueryContext(ctx, fmt.Sprintf(`
		SELECT id FROM %s
		WHERE id LIKE CONCAT(?, '.%%')
		  AND id NOT LIKE CONCAT(?, '.%%.%%')
	`, issueTable), parentID, parentID)
	if err != nil {
		return "", fmt.Errorf("get next child ID: query existing children: %w", err)
	}
	defer rows.Close()

	for rows.Next() {
		var id string
		if err := rows.Scan(&id); err != nil {
			return "", fmt.Errorf("get next child ID: scan child row: %w", err)
		}
		_, childNum, ok := ParseHierarchicalID(id)
		if ok && childNum > lastChild {
			lastChild = childNum
		}
	}
	if err := rows.Err(); err != nil {
		return "", fmt.Errorf("get next child ID: iterate children: %w", err)
	}

	nextChild := lastChild + 1

	//nolint:gosec // G201: counterTable is one of two hardcoded constants.
	if _, err := tx.ExecContext(ctx, fmt.Sprintf(`
		INSERT INTO %s (parent_id, last_child) VALUES (?, ?)
		ON DUPLICATE KEY UPDATE last_child = ?
	`, counterTable), parentID, nextChild, nextChild); err != nil {
		return "", fmt.Errorf("get next child ID: update counter: %w", err)

View on GitHub (pinned to 71377f2769)

Solutions

  1. Inspect and repair the issues table rows for the affected parent (check for NULL/corrupt id values).
  2. Retry the operation; mid-iteration connection drops are usually transient.
  3. If corruption is suspected, restore from git-tracked issues.jsonl export and re-import.
  4. Check wrapped error text: 'converting NULL to string' points at bad rows; 'connection refused/bad connection' points at the server.
Defensive patterns

Strategy: retry

Try / catch

if err != nil {
    tx.Rollback()
    if strings.Contains(err.Error(), "connection") { return retry(err) }
    return fmt.Errorf("corrupt child row: %w", err)
}

Prevention

When it happens

Trigger: Iterating results of the child-ID LIKE query when: a row's id value cannot be converted to string (corrupt or NULL row), or the underlying connection drops mid-iteration so the driver cannot fetch the next row.

Common situations: Corrupted database files after a crash; NULL or binary data in the id column from manual edits; network interruption during a large result-set scan against a remote Dolt server.

Related errors


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