hashicorp / hashicorp/go-multierror

Can panic-recover handling add to the function Group.Go()?

Open
#83 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
2.6k
Forks
143
PR merge metrics
No merged PRs in 30d

Description

When the program is processed in multiple goroutines, panic may occur, which will cause main goroutine to crash directly. Can following logic add to Group.Go() ?

```diff
// Go calls the given function in a new goroutine.
//
// If the function returns an error it is added to the group multierror which
// is returned by Wait.
func (g *Group) Go(f func() error) {
g.wg.Add(1)

go func() {
defer g.wg.Done()

+ defer func() {
+ if r := recover(); r != nil {
+ g.mutex.Lock()
+ g.err = Append(g.err, fmt.Errorf("%v", r))
+ g.mutex.Unlock()
+ }
+ }()

if err := f(); err != nil {
g.mutex.Lock()
g.err = Append(g.err, err)
g.mutex.Unlock()
}
}()
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.