gastownhall/beads · error

line %d: %w

Error message

line %d: %w

What it means

`parseBatchScript` tokenizes each non-blank, non-comment line of a batch script; if `tokenizeBatchLine` fails (currently only for an unterminated quoted string), the error is wrapped with the 1-based line number. Parsing happens fully before any writes, so a tokenization error aborts the entire batch with no side effects.

Source

Thrown at cmd/bd/batch.go:258

// non-comment line. It rejects unknown commands immediately so a bad script
// fails before any writes.
func parseBatchScript(r io.Reader) ([]batchOp, error) {
	scanner := bufio.NewScanner(r)
	// Allow long lines (descriptions, multi-token updates).
	scanner.Buffer(make([]byte, 64*1024), 4*1024*1024)

	var ops []batchOp
	lineNo := 0
	for scanner.Scan() {
		lineNo++
		raw := scanner.Text()
		trimmed := strings.TrimSpace(raw)
		if trimmed == "" || strings.HasPrefix(trimmed, "#") {
			continue
		}
		tokens, err := tokenizeBatchLine(trimmed)
		if err != nil {
			return nil, fmt.Errorf("line %d: %w", lineNo, err)
		}
		if len(tokens) == 0 {
			continue
		}
		op := batchOp{line: lineNo, raw: trimmed}
		switch tokens[0] {
		case "close":
			op.cmd = "close"
			op.args = tokens[1:]
		case "update":
			op.cmd = "update"
			op.args = tokens[1:]
		case "create":
			op.cmd = "create"
			op.args = tokens[1:]
		case "dep":
			if len(tokens) < 2 {
				return nil, fmt.Errorf("line %d: 'dep' requires a subcommand (add|remove)", lineNo)

View on GitHub (pinned to 71377f2769)

Solutions

  1. Go to the reported line number and close the opening double quote.
  2. Escape embedded quotes as \" inside double-quoted strings.
  3. If the quote is unnecessary, remove it — quoting is only needed for values with spaces/tabs.
  4. Run `bd batch --dry-run` to validate the whole script before executing.

Example fix

// before (batch file)
update bd-1 "status in review
// after
update bd-1 "status in review"
Defensive patterns

Strategy: validation

Validate before calling

# Validate the batch script before executing:
bd batch --dry-run -f batch.txt || echo "fix the reported line"
# Or check quoting per line in shell:
awk '{ n=gsub(/"/,"",$0); if (n % 2 != 0) print "unbalanced quote at line " NR ": " $0 }' batch.txt

Try / catch

ops, err := parseBatchInput(r)
if err != nil {
    if strings.Contains(err.Error(), "line ") {
        return fmt.Errorf("batch script rejected before any writes: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: A batch script line contains an opening double quote that is never closed, e.g. `update bd-1 "half done` piped to `bd batch` or passed via `-f script.txt`.

Common situations: Descriptions containing quotes where the closing quote got lost by shell escaping; heredocs/CI scripts with truncated lines; generating batch files programmatically without escaping `"` inside quoted values.

Related errors


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