gastownhall/beads · error
parsing batch input: %w
Error message
parsing batch input: %w
What it means
After obtaining the batch reader (file or stdin), the script is parsed by parseBatchScript. Any syntax or semantic error in the batch script is wrapped as 'parsing batch input: %w', so the user sees the parser's specific complaint (bad line, unknown command, malformed arguments) alongside the batch context.
Source
Thrown at cmd/bd/batch.go:121
filePath, _ := cmd.Flags().GetString("file")
dryRun, _ := cmd.Flags().GetBool("dry-run")
commitMsg, _ := cmd.Flags().GetString("message")
var reader io.Reader
if filePath != "" {
f, err := os.Open(filePath) // #nosec G304 -- user-supplied batch file
if err != nil {
return fmt.Errorf("open batch file: %w", err)
}
defer f.Close()
reader = f
} else {
reader = cmd.InOrStdin()
}
ops, err := parseBatchScript(reader)
if err != nil {
return fmt.Errorf("parsing batch input: %w", err)
}
if dryRun {
// In dry-run mode, just echo what would run. This is helpful for
// shell script authors verifying their scripts before running.
for _, op := range ops {
fmt.Fprintf(cmd.OutOrStdout(), "line %d: %s\n", op.line, op.raw)
}
if jsonOutput {
if err := outputJSON(map[string]interface{}{
"dry_run": true,
"operations": len(ops),
}); err != nil {
return err
}
} else {
fmt.Fprintf(cmd.OutOrStdout(), "%d operations parsed (dry-run, nothing executed)\n", len(ops))
}View on GitHub (pinned to 71377f2769)
Solutions
- Read the wrapped parser error to find the offending line and fix the batch syntax
- Validate the script with 'bd batch --dry-run --file <file>' before applying
- Re-generate the batch file ensuring one well-formed operation per line
- Check encoding artifacts (CRLF, BOM) — convert to plain LF UTF-8
Example fix
// before crate issue "Fix bug" # typo'd keyword // after bd batch --dry-run --file ops.txt # validate first create issue "Fix bug" -p 1
Defensive patterns
Strategy: validation
Validate before calling
// validate before applying
if err := validateBatchScript(contents); err != nil {
return fmt.Errorf("invalid batch script: %w", err)
} Try / catch
ops, err := parseBatchScript(reader)
if err != nil {
return fmt.Errorf("parsing batch input: %w\nFix the script or validate with 'bd batch --dry-run'", err)
} Prevention
- Always smoke-test with 'bd batch --dry-run' before a real run
- Generate batch files programmatically with well-formed one-operation-per-line syntax
- Normalize line endings (LF) and strip BOM from generated scripts
- Never pipe arbitrary command output directly into bd batch without checking its format
When it happens
Trigger: parseBatchScript(reader) returns an error — malformed batch line syntax, unsupported operation keyword, wrong number of arguments for an operation, or invalid characters/encoding in the batch file/stdin.
Common situations: Hand-written batch scripts with syntax mistakes; batch file produced by another tool with wrong quoting; CRLF line endings or BOM confusing the parser; piping output of a command that emitted non-batch text; empty or truncated file.
Related errors
- line %d: %w
- dolt version output is unparseable
- no database connection available (%s)
- open batch file: %w
- line %d (%s): %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/c3a899773bd8358d.
Report an issue: GitHub.