@@ -105,8 +105,10 @@ func NewScriptRegistry() *ScriptRegistry {
105105//
106106// If a script with the same name already exists, it will be overwritten.
107107// This is useful for testing but should be avoided in production.
108- func (r * ScriptRegistry ) Register (name string , source string ) {
109- r .RegisterWithMode (name , source , RuntimeModeGitHubScript )
108+ //
109+ // Returns an error if validation fails.
110+ func (r * ScriptRegistry ) Register (name string , source string ) error {
111+ return r .RegisterWithMode (name , source , RuntimeModeGitHubScript )
110112}
111113
112114// RegisterWithMode adds a script source to the registry with a specific runtime mode.
@@ -125,9 +127,9 @@ func (r *ScriptRegistry) Register(name string, source string) {
125127// - GitHub Script mode: validates no execSync usage (should use exec instead)
126128// - Node.js mode: validates no GitHub Actions globals (core.*, exec.*, github.*)
127129//
128- // Panics if validation fails, as this indicates a programming error that should be
129- // caught during development and testing .
130- func (r * ScriptRegistry ) RegisterWithMode (name string , source string , mode RuntimeMode ) {
130+ // Returns an error if validation fails, allowing the caller to handle gracefully
131+ // instead of crashing the process .
132+ func (r * ScriptRegistry ) RegisterWithMode (name string , source string , mode RuntimeMode ) error {
131133 r .mu .Lock ()
132134 defer r .mu .Unlock ()
133135
@@ -137,20 +139,20 @@ func (r *ScriptRegistry) RegisterWithMode(name string, source string, mode Runti
137139
138140 // Perform compile-time validation based on runtime mode
139141 if err := validateNoExecSync (name , source , mode ); err != nil {
140- // This is a programming error that should be caught during development
141- panic (fmt .Sprintf ("Script registration validation failed: %v" , err ))
142+ return fmt .Errorf ("script registration validation failed for %q: %w" , name , err )
142143 }
143144
144145 if err := validateNoGitHubScriptGlobals (name , source , mode ); err != nil {
145- // This is a programming error that should be caught during development
146- panic (fmt .Sprintf ("Script registration validation failed: %v" , err ))
146+ return fmt .Errorf ("script registration validation failed for %q: %w" , name , err )
147147 }
148148
149149 r .scripts [name ] = & scriptEntry {
150150 source : source ,
151151 mode : mode ,
152152 actionPath : "" , // No custom action by default
153153 }
154+
155+ return nil
154156}
155157
156158// RegisterWithAction registers a script with both inline code and a custom action path.
@@ -166,7 +168,10 @@ func (r *ScriptRegistry) RegisterWithMode(name string, source string, mode Runti
166168// The actionPath should be a relative path from the repository root for development mode.
167169// In the future, this can be extended to support versioned references like
168170// "githubnext/gh-aw/.github/actions/create-issue@SHA" for release mode.
169- func (r * ScriptRegistry ) RegisterWithAction (name string , source string , mode RuntimeMode , actionPath string ) {
171+ //
172+ // Returns an error if validation fails, allowing the caller to handle gracefully
173+ // instead of crashing the process.
174+ func (r * ScriptRegistry ) RegisterWithAction (name string , source string , mode RuntimeMode , actionPath string ) error {
170175 r .mu .Lock ()
171176 defer r .mu .Unlock ()
172177
@@ -177,18 +182,20 @@ func (r *ScriptRegistry) RegisterWithAction(name string, source string, mode Run
177182
178183 // Perform compile-time validation based on runtime mode
179184 if err := validateNoExecSync (name , source , mode ); err != nil {
180- panic ( fmt .Sprintf ( "Script registration validation failed: %v " , err ) )
185+ return fmt .Errorf ( "script registration validation failed for %q : %w " , name , err )
181186 }
182187
183188 if err := validateNoGitHubScriptGlobals (name , source , mode ); err != nil {
184- panic ( fmt .Sprintf ( "Script registration validation failed: %v " , err ) )
189+ return fmt .Errorf ( "script registration validation failed for %q : %w " , name , err )
185190 }
186191
187192 r .scripts [name ] = & scriptEntry {
188193 source : source ,
189194 mode : mode ,
190195 actionPath : actionPath ,
191196 }
197+
198+ return nil
192199}
193200
194201// GetActionPath retrieves the custom action path for a script, if registered.
0 commit comments