hashicorp / hashicorp/go-multierror
Can panic-recover handling add to the function Group.Go()?
- 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.