From 85ff5ece6bd832e588b0a89a1d0c25b476e4646b Mon Sep 17 00:00:00 2001 From: bufdev Date: Thu, 31 Oct 2024 15:28:52 -0400 Subject: [PATCH] commit --- private/buf/bufgen/generator.go | 7 ------- private/pkg/thread/thread.go | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/private/buf/bufgen/generator.go b/private/buf/bufgen/generator.go index 6ed086584b..8ad3ab6853 100644 --- a/private/buf/bufgen/generator.go +++ b/private/buf/bufgen/generator.go @@ -295,13 +295,6 @@ func (g *generator) execPlugins( jobs, thread.ParallelizeWithCancelOnFailure(), ); err != nil { - // Handle errors joined with `errors.Join`, which is documented to fulfill this interface. - if unwrappableErr, ok := err.(interface{ Unwrap() []error }); ok { - errs := unwrappableErr.Unwrap() - if len(errs) > 0 { - return nil, errs[0] - } - } return nil, err } if err := validateResponses(responses, pluginConfigs); err != nil { diff --git a/private/pkg/thread/thread.go b/private/pkg/thread/thread.go index bad9c4b448..b50d54ab6d 100644 --- a/private/pkg/thread/thread.go +++ b/private/pkg/thread/thread.go @@ -73,7 +73,7 @@ func Parallelize(ctx context.Context, jobs []func(context.Context) error, option defer cancel() } semaphoreC := make(chan struct{}, Parallelism()*multiplier) - var retErr error + var errs []error var wg sync.WaitGroup var lock sync.Mutex var stop bool @@ -90,19 +90,19 @@ func Parallelize(ctx context.Context, jobs []func(context.Context) error, option select { case <-ctx.Done(): stop = true - retErr = errors.Join(retErr, ctx.Err()) + errs = append(errs, ctx.Err()) case semaphoreC <- struct{}{}: select { case <-ctx.Done(): stop = true - retErr = errors.Join(retErr, ctx.Err()) + errs = append(errs, ctx.Err()) default: job := job wg.Add(1) go func() { if err := job(ctx); err != nil { lock.Lock() - retErr = errors.Join(retErr, err) + errs = append(errs, err) lock.Unlock() if cancel != nil { cancel() @@ -116,7 +116,14 @@ func Parallelize(ctx context.Context, jobs []func(context.Context) error, option } } wg.Wait() - return retErr + switch len(errs) { + case 0: + return nil + case 1: + return errs[0] + default: + return errors.Join(errs...) + } } // ParallelizeOption is an option to Parallelize.