Skip to content

Replace panic calls with proper error propagation#530

Open
swell-agent wants to merge 2 commits intowavesplatform:mainfrom
swell-agent:issue-409
Open

Replace panic calls with proper error propagation#530
swell-agent wants to merge 2 commits intowavesplatform:mainfrom
swell-agent:issue-409

Conversation

@swell-agent
Copy link

Summary

Closes #409

  • Replace all panic() calls with structured error handling using buffered channels and select-based multiplexing
  • Add ServeErr() channel to API and BotAPI for HTTP server error reporting
  • Convert runMessagingClients/runMessagingServices to return error channels
  • Use FanInCtx with proper context cancellation for composing error sources in nodemon
  • Fix nil pointer dereference in vault.go when login fails with context.Canceled
  • Ensure scheduler shutdown runs on all exit paths in discord/telegram bot binaries
  • Log shutdown reason on service failure in nodemon
  • Simplify statementLogWrapper.String() and BaseTargetAlert.Message() error handling

Test plan

  • make completes without errors
  • No panic calls remain in the codebase
  • New tests pass: api_nopanic_test.go, alerts_nopanic_test.go
  • Verify graceful shutdown on SIGTERM
  • Verify error propagation when messaging client fails

🤖 Generated with Claude Code

Replace all panic() calls with structured error handling using buffered
channels and select-based multiplexing. Errors from goroutines are now
propagated to callers instead of crashing the process.

Key changes:
- Add ServeErr() channel to API and BotAPI for HTTP server error reporting
- Convert runMessagingClients/Services to return error channels
- Use FanInCtx for composing error sources with proper context cancellation
- Fix nil pointer dereference in vault.go when login fails with context.Canceled
- Ensure scheduler shutdown runs on all exit paths in bot binaries
- Log shutdown reason on service failure in nodemon
- Simplify statementLogWrapper.String() and BaseTargetAlert.Message()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
responseChan chan pair.Response,
) {
) <-chan error {
errCh := make(chan error, 2) //nolint:mnd // two goroutines
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove this directive as suggested by golangci-lint.


func TestBotAPIServeErrChannel(t *testing.T) {
t.Parallel()
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, fix the linter issue as suggested.

pairResponse chan<- pair.Response,
) {
) <-chan error {
errCh := make(chan error, 2) //nolint:mnd // two goroutines
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this directive because it's unused.


func TestAPIServeErrChannel(t *testing.T) {
t.Parallel()
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, fix linter issue as suggested.

Remove unused //nolint:mnd directives in discord and telegram bots.
Replace slog.NewTextHandler(io.Discard, nil) with slog.DiscardHandler
in test files.
Comment on lines +61 to +65
if loginErr != nil {
if !errors.Is(loginErr, context.Canceled) {
logger.Error("Unable to authenticate to Vault, stopping token renewal", attrs.Error(loginErr))
}
return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do exponential backoff with maximum backoff limit, not return. return here just stops the renew cycle.

logger.Error("Unable to start managing token lifecycle", attrs.Error(tokenErr))
panic(tokenErr)
logger.Error("Unable to start managing token lifecycle, stopping token renewal", attrs.Error(tokenErr))
return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do exponential backoff with maximum backoff limit, not return. return here just stops the renew cycle.

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.

Get rid of panic calls

3 participants