Skip to content

[Code Quality] Add panic recovery to critical compilation paths #13787

@github-actions

Description

@github-actions

Description

Implement panic recovery (defer recover()) in critical compilation and GitHub API operation paths to prevent workflow crashes from unexpected panics. Currently zero panic recovery implementations exist across the entire codebase.

Problem

Complex operations (compilation, GitHub API calls, file I/O, JSON parsing) lack safety nets. A single unhandled panic in production crashes entire workflow runs, resulting in poor error messages and production incidents.

Suggested Changes

Files to Update

  • pkg/workflow/compiler.go - Main compilation entry points
  • pkg/workflow/compiler_yaml.go - YAML generation operations
  • pkg/cli/trial_command.go - Trial workflow execution
  • pkg/cli/add_interactive.go - Interactive workflow creation
  • pkg/cli/init.go - Repository initialization

Implementation Pattern

func CriticalOperation() (err error) {
    defer func() {
        if r := recover(); r != nil {
            err = fmt.Errorf("panic during operation: %v\nstack trace:\n%s", 
                r, string(debug.Stack()))
            
            if log.Enabled() {
                log.Printf("Recovered from panic: %v", r)
            }
        }
    }()
    
    // Existing operation code...
    return nil
}

Success Criteria

  • Add panic recovery to main compiler entry points (Compile, CompileWorkflow, CompileAction)
  • Add panic recovery to GitHub API client operations
  • Add panic recovery to interactive CLI commands (init, add, trial)
  • Recovered panics converted to proper errors with stack traces in debug logs
  • Add test cases verifying panic recovery converts to errors

Testing

func TestCompiler_PanicRecovery(t *testing.T) {
    tests := []struct {
        name      string
        setupPanic func()
        wantErr   string
    }{
        {
            name: "nil pointer panic",
            setupPanic: func() { var x *int; _ = *x },
            wantErr: "panic during",
        },
    }
    
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            err := recoverableOperation(tt.setupPanic)
            assert.Error(t, err)
            assert.Contains(t, err.Error(), tt.wantErr)
        })
    }
}

Source

Extracted from Error Experience Engineering Discussion #12265

Priority

High - Prevents production crashes from unexpected panics

Estimated Effort

Medium (2-3 days)

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 18, 2026, 9:08 PM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions