Skip to content

fix(shims): resolve Windows batch file syntax error in generated shims#556

Merged
ChronosMasterOfAllTime merged 5 commits into
mainfrom
fix/issue/555
Jun 3, 2026
Merged

fix(shims): resolve Windows batch file syntax error in generated shims#556
ChronosMasterOfAllTime merged 5 commits into
mainfrom
fix/issue/555

Conversation

@ChronosMasterOfAllTime

Copy link
Copy Markdown
Contributor

Summary

Fixes #555

Resolves Windows batch file syntax errors in generated .bat shims that caused ") was unexpected at this time" errors when running Go commands on Windows.

Problem

The Windows shim template in internal/shims/manager.go contained problematic CMD batch syntax:

  1. goto command and label (:found_file) inside a parenthesized if (...) block
  2. Direct %* expansion inside nested for (...) do (...) block

These patterns break Windows CMD parsing and prevented all shim-based commands from executing.

Solution

  • Moved file argument detection to a safe subroutine (:detect_file_arg)
  • Use call :detect_file_arg %* instead of inline goto/label
  • Added explicit exit code propagation with exit /b %ERRORLEVEL%
  • Simplified GOENV_DEBUG handling to single-line conditional

Testing

  • ✅ All existing Go tests pass (go test -v ./cmd/shims/... ./internal/shims/...)
  • ✅ Follows the safer batch file approach suggested in the issue report
  • ✅ Template generates valid CMD syntax compatible with both cmd.exe and PowerShell

Notes

This fix applies to all generated shims (go.bat, gofmt.bat, golangci-lint.bat, etc.) as they all use the same template.

Fixes #555

The Windows .bat shim template contained problematic syntax that broke
CMD batch file parsing:
- goto/label (:found_file) inside parenthesized if (...) block
- Direct %* expansion inside nested for (...) do (...) block

These caused 'was unexpected at this time' errors when running any
Go command through the shims on Windows.

Solution:
- Move file argument detection to a safe subroutine (:detect_file_arg)
- Call subroutine using 'call' instead of inline goto/label
- Add explicit exit code propagation with exit /b %ERRORLEVEL%

This matches the safer approach suggested in the issue report and
ensures shims work correctly in both cmd.exe and PowerShell.
Provides comprehensive guidance for AI coding assistants including:
- Branch structure and PR guidelines (main vs master)
- Platform-specific constraints (Windows batch file gotchas)
- Development patterns and testing guidelines
- Common tasks and issue resolution checklist

This helps AI agents understand project conventions and avoid
common pitfalls like Windows batch file syntax errors.
Root-level AI agent instructions that complement .github/copilot-instructions.md.
Provides quick-start guidance, architecture overview, and critical Windows
development constraints.

Multiple locations ensure broader AI tool compatibility:
- AGENTS.md (root) - discovered by most AI systems
- .github/copilot-instructions.md - GitHub Copilot specific
Enhanced AI agent documentation with:

Testing Standards:
- Testing philosophy (TDD, coverage goals, performance)
- Environment requirements (unset GOENV_DEBUG critical for tests)
- Complete test targets reference (make test, test-quick, test-verbose, etc.)
- Test organization patterns and naming conventions
- Platform-specific testing (Unix/Windows validation)
- Test artifacts locations (.test-results/)
- PR requirements checklist
- Common testing commands quick reference

Directory Structure:
- Complete cmd/ directory reference (12 command categories)
- Complete internal/ directory reference (31 packages)
- Clear separation of concerns and package purposes

This comprehensive documentation eliminates the need to rebuild context
for each PR and ensures consistent development practices across the project.
@ChronosMasterOfAllTime ChronosMasterOfAllTime merged commit 09be2c9 into main Jun 3, 2026
11 checks passed
@ChronosMasterOfAllTime ChronosMasterOfAllTime deleted the fix/issue/555 branch June 3, 2026 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant