Skip to content

Commit

Permalink
fix: recover from panic
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenrinzema committed Dec 14, 2023
1 parent 46ef6fc commit ae91cf5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wire

import (
"context"
"fmt"
"sync"

"github.com/jeroenrinzema/psql-wire/pkg/buffer"
Expand Down Expand Up @@ -100,7 +101,14 @@ func (cache *DefaultPortalCache) Get(ctx context.Context, name string) (*Portal,
return portal, nil
}

func (cache *DefaultPortalCache) Execute(ctx context.Context, name string, writer *buffer.Writer) error {
func (cache *DefaultPortalCache) Execute(ctx context.Context, name string, writer *buffer.Writer) (err error) {
defer func() {
r := recover()
if r != nil {
err = fmt.Errorf("unexpected panic: %s", r)
}
}()

cache.mu.Lock()
defer cache.mu.Unlock()

Expand All @@ -113,5 +121,10 @@ func (cache *DefaultPortalCache) Execute(ctx context.Context, name string, write
return nil
}

return portal.statement.fn(ctx, NewDataWriter(ctx, portal.statement.columns, portal.formats, writer), portal.parameters)
err = portal.statement.fn(ctx, NewDataWriter(ctx, portal.statement.columns, portal.formats, writer), portal.parameters)
if err != nil {
return err
}

return err
}

0 comments on commit ae91cf5

Please sign in to comment.