-
Notifications
You must be signed in to change notification settings - Fork 36
Closed as not planned
Labels
Description
Objective
Add panic recovery mechanisms with proper error conversion for critical operations in workflow compilation, MCP server initialization, and CLI orchestration.
Context
Currently 0 defer recover() implementations exist, leaving crashes unhandled. Adding panic recovery to critical entry points improves stability and provides graceful error messages instead of crashes.
Files to Modify
Critical operation entry points:
pkg/workflow/compiler_orchestrator.go-CompileWorkflow()pkg/workflow/mcp-config.go-GenerateMCPConfig()pkg/cli/compile_command.go-RunCompile()pkg/cli/run_command.go-RunWorkflow()
Approach
Add panic recovery to critical entry points:
import (
"runtime/debug"
"github.com/githubnext/gh-aw/pkg/logger"
)
var log = logger.New("workflow:compiler")
func CriticalOperation() (err error) {
defer func() {
if r := recover(); r != nil {
log.Printf("Panic recovered: %v\nStack: %s", r, debug.Stack())
err = fmt.Errorf("internal error during compilation: %v. This is a bug - please report it at github.com/githubnext/gh-aw/issues", r)
}
}()
// Critical operation that might panic
return doWork()
}Key principles:
- Log panic details with stack traces for debugging
- Convert panics to user-friendly error messages
- Never silently swallow panics (always log)
- Include "this is a bug" messaging to encourage reporting
- Named return value (
err error) to enable error assignment in defer
Acceptance Criteria
- Panic recovery added to 4 critical entry points
- Recovered panics converted to proper errors with context
- Debug logging captures panic details with stack traces
- Users see graceful error messages instead of crashes
- Tests verify panic recovery behavior
- Error messages include link to GitHub issues
Testing
Add tests for panic recovery:
func TestCompileWorkflow_PanicRecovery(t *testing.T) {
// Test that panics are recovered and converted to errors
// Mock a function that panics during compilation
}Run validation:
make test
# Verify panic recovery added
grep -r "defer.*recover" pkg/workflow/ pkg/cli/ | wc -lRelated to #9236
AI generated by Plan Command for discussion #9231
Copilot