diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-10 23:59:21 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-10 23:59:21 +0300 |
| commit | 72ac39cb2bac5c176dd1277c9482334d0441286f (patch) | |
| tree | 91c68a1f03f0da64a6380f90643dc108e133f8de /internal/hexaicli | |
| parent | b9f90b4ffa8260cc906fa1b195ed0ba4aaa211df (diff) | |
Replace panics with returned errors in llm.RegisterProvider
RegisterProvider now returns an error for an empty name, a nil factory,
or a duplicate registration instead of panicking, making registration
composable and testable without recover(). RegisterAllProviders caches
the one-time registration error (sync.Once cannot return a value) and
returns it to every caller.
Updated all call sites: hexailsp, hexaicli and hexaiaction propagate the
error with context; test TestMains fail fast via panic. Added unit tests
covering empty name, nil factory, duplicate, success and idempotent
re-registration.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/hexaicli')
| -rw-r--r-- | internal/hexaicli/run.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/internal/hexaicli/run.go b/internal/hexaicli/run.go index df37f82..94dcd12 100644 --- a/internal/hexaicli/run.go +++ b/internal/hexaicli/run.go @@ -92,7 +92,9 @@ func cliTemperatureFromEntry(cfg appconfig.App, provider string, entry appconfig // Run executes the Hexai CLI behavior given arguments and I/O streams. // It assumes flags have already been parsed by the caller. func Run(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) error { - llm.RegisterAllProviders() + if err := llm.RegisterAllProviders(); err != nil { + return fmt.Errorf("failed to register LLM providers: %w", err) + } return NewRunner().Run(ctx, args, stdin, stdout, stderr) } |
