{"record":{"id":"c3a899773bd8358d","repo":"gastownhall/beads","slug":"parsing-batch-input-w","errorCode":null,"errorMessage":"parsing batch input: %w","messagePattern":"parsing batch input: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/batch.go","lineNumber":121,"sourceCode":"\t\tfilePath, _ := cmd.Flags().GetString(\"file\")\n\t\tdryRun, _ := cmd.Flags().GetBool(\"dry-run\")\n\t\tcommitMsg, _ := cmd.Flags().GetString(\"message\")\n\n\t\tvar reader io.Reader\n\t\tif filePath != \"\" {\n\t\t\tf, err := os.Open(filePath) // #nosec G304 -- user-supplied batch file\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"open batch file: %w\", err)\n\t\t\t}\n\t\t\tdefer f.Close()\n\t\t\treader = f\n\t\t} else {\n\t\t\treader = cmd.InOrStdin()\n\t\t}\n\n\t\tops, err := parseBatchScript(reader)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"parsing batch input: %w\", err)\n\t\t}\n\n\t\tif dryRun {\n\t\t\t// In dry-run mode, just echo what would run. This is helpful for\n\t\t\t// shell script authors verifying their scripts before running.\n\t\t\tfor _, op := range ops {\n\t\t\t\tfmt.Fprintf(cmd.OutOrStdout(), \"line %d: %s\\n\", op.line, op.raw)\n\t\t\t}\n\t\t\tif jsonOutput {\n\t\t\t\tif err := outputJSON(map[string]interface{}{\n\t\t\t\t\t\"dry_run\":    true,\n\t\t\t\t\t\"operations\": len(ops),\n\t\t\t\t}); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfmt.Fprintf(cmd.OutOrStdout(), \"%d operations parsed (dry-run, nothing executed)\\n\", len(ops))\n\t\t\t}","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/batch.go#L103-L139","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ncrate issue \"Fix bug\"          # typo'd keyword\n// after\nbd batch --dry-run --file ops.txt   # validate first\ncreate issue \"Fix bug\" -p 1","handlingStrategy":"validation","validationCode":"// validate before applying\nif err := validateBatchScript(contents); err != nil {\n\treturn fmt.Errorf(\"invalid batch script: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"ops, err := parseBatchScript(reader)\nif err != nil {\n\treturn fmt.Errorf(\"parsing batch input: %w\\nFix the script or validate with 'bd batch --dry-run'\", err)\n}","preventionTips":["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"],"tags":["parsing","batch","script","go"],"backgroundTag":"batch-script-parse-error","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}