Skip to content

Commit fe428b2

Browse files
lib/errors: new MultiError error type and utilities (sourcegraph#31466)
Wholesale migration away from go-multierror into a custom multierror implementation that is fully compatible with cockroachdb/errors, prints all errors, can be introspected with Is, As, and friends, and more. The new MultiError type is only available as an interface. Co-authored-by: Camden Cheek <[email protected]>
1 parent eb45d57 commit fe428b2

66 files changed

Lines changed: 681 additions & 234 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ run:
7373
# whenever we reference a file here it's relative to its containing workspace.
7474
# These values are under the ./lib module.
7575
- errors/cockroach.go
76-
- errors/multierror.go
7776

7877
# These are all projects with distinct go.mod files that can't import lib
7978
# due to not knowing an absolute path to the user's sourcegraph directory

enterprise/cmd/executor/internal/command/logger.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type Logger struct {
8585

8686
replacer *strings.Replacer
8787

88-
errs *errors.MultiError
88+
errs error
8989
errsMu sync.Mutex
9090
}
9191

@@ -112,7 +112,7 @@ func NewLogger(store ExecutionLogEntryStore, job executor.Job, recordID int, rep
112112
done: make(chan struct{}),
113113
handles: make(chan *entryHandle, logEntryBufsize),
114114
replacer: strings.NewReplacer(oldnew...),
115-
errs: &errors.MultiError{},
115+
errs: nil,
116116
}
117117

118118
go l.writeEntries()
@@ -130,7 +130,7 @@ func (l *Logger) Flush() error {
130130
l.errsMu.Lock()
131131
defer l.errsMu.Unlock()
132132

133-
return l.errs.ErrorOrNil()
133+
return l.errs
134134
}
135135

136136
// Log redacts secrets from the given log entry and stores it.

enterprise/cmd/frontend/internal/batches/resolvers/changeset_apply_preview_connection.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ type publicationStateMap map[string]batches.PublishedValue
412412
func newPublicationStateMap(in *[]graphqlbackend.ChangesetSpecPublicationStateInput) (publicationStateMap, error) {
413413
out := publicationStateMap{}
414414
if in != nil {
415-
var errs *errors.MultiError
415+
var errs error
416416
for _, ps := range *in {
417417
id, err := unmarshalChangesetSpecID(ps.ChangesetSpec)
418418
if err != nil {
@@ -426,8 +426,8 @@ func newPublicationStateMap(in *[]graphqlbackend.ChangesetSpecPublicationStateIn
426426
}
427427
out[id] = ps.PublicationState
428428
}
429-
if err := errs.ErrorOrNil(); err != nil {
430-
return nil, err
429+
if errs != nil {
430+
return nil, errs
431431
}
432432
}
433433

enterprise/cmd/frontend/internal/batches/resolvers/resolver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func (r *Resolver) ApplyBatchChange(ctx context.Context, args *graphqlbackend.Ap
443443
}
444444

445445
func addPublicationStatesToOptions(in *[]graphqlbackend.ChangesetSpecPublicationStateInput, opts *service.UiPublicationStates) error {
446-
var errs *errors.MultiError
446+
var errs error
447447

448448
if in != nil && *in != nil {
449449
for _, state := range *in {
@@ -459,7 +459,7 @@ func addPublicationStatesToOptions(in *[]graphqlbackend.ChangesetSpecPublication
459459

460460
}
461461

462-
return errs.ErrorOrNil()
462+
return errs
463463
}
464464

465465
func (r *Resolver) applyOrCreateBatchChange(ctx context.Context, args *graphqlbackend.ApplyBatchChangeArgs, opts service.ApplyBatchChangeOpts) (*btypes.BatchChange, error) {

enterprise/cmd/frontend/internal/batches/webhooks/bitbucketserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (h *BitbucketServerWebhook) ServeHTTP(w http.ResponseWriter, r *http.Reques
5151

5252
prs, ev := h.convertEvent(e)
5353

54-
m := new(errors.MultiError)
54+
var m error
5555
for _, pr := range prs {
5656
if pr == (PR{}) {
5757
log15.Warn("Dropping Bitbucket Server webhook event", "type", fmt.Sprintf("%T", e))
@@ -63,7 +63,7 @@ func (h *BitbucketServerWebhook) ServeHTTP(w http.ResponseWriter, r *http.Reques
6363
m = errors.Append(m, err)
6464
}
6565
}
66-
if m.ErrorOrNil() != nil {
66+
if m != nil {
6767
respond(w, http.StatusInternalServerError, m)
6868
}
6969
}

enterprise/cmd/frontend/internal/batches/webhooks/github.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (h *GitHubWebhook) Register(router *webhooks.GitHubWebhook) {
5454
// handleGithubWebhook is the entry point for webhooks from the webhook router, see the events
5555
// it's registered to handle in GitHubWebhook.Register
5656
func (h *GitHubWebhook) handleGitHubWebhook(ctx context.Context, extSvc *types.ExternalService, payload interface{}) error {
57-
m := new(errors.MultiError)
57+
var m error
5858
externalServiceID, err := extractExternalServiceID(extSvc)
5959
if err != nil {
6060
return err
@@ -72,7 +72,7 @@ func (h *GitHubWebhook) handleGitHubWebhook(ctx context.Context, extSvc *types.E
7272
m = errors.Append(m, err)
7373
}
7474
}
75-
return m.ErrorOrNil()
75+
return m
7676
}
7777

7878
func (h *GitHubWebhook) convertEvent(ctx context.Context, externalServiceID string, theirs interface{}) (prs []PR, ours keyer) {

enterprise/cmd/frontend/internal/codeintel/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ func (c *Config) Load() {
2727
}
2828

2929
func (c *Config) Validate() error {
30-
var errs *errors.MultiError
30+
var errs error
3131
errs = errors.Append(errs, c.BaseConfig.Validate())
3232
errs = errors.Append(errs, c.LSIFUploadStoreConfig.Validate())
3333
errs = errors.Append(errs, c.AutoIndexEnqueuerConfig.Validate())
34-
return errs.ErrorOrNil()
34+
return errs
3535
}

enterprise/cmd/precise-code-intel-worker/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ func (c *Config) Load() {
2727
}
2828

2929
func (c *Config) Validate() error {
30-
var errs *errors.MultiError
30+
var errs error
3131
errs = errors.Append(errs, c.BaseConfig.Validate())
3232
errs = errors.Append(errs, c.LSIFUploadStoreConfig.Validate())
33-
return errs.ErrorOrNil()
33+
return errs
3434
}

enterprise/cmd/worker/internal/batches/janitor/janitor_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func (c *janitorConfig) Load() {
2020
}
2121

2222
func (c *janitorConfig) Validate() error {
23-
var errs *errors.MultiError
23+
var errs error
2424
errs = errors.Append(errs, c.BaseConfig.Validate())
2525
errs = errors.Append(errs, c.MetricsConfig.Validate())
26-
return errs.ErrorOrNil()
26+
return errs
2727
}

enterprise/cmd/worker/internal/codeintel/indexing_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func (c *indexingConfig) Load() {
3636
}
3737

3838
func (c *indexingConfig) Validate() error {
39-
var errs *errors.MultiError
39+
var errs error
4040
errs = errors.Append(errs, c.BaseConfig.Validate())
4141
errs = errors.Append(errs, c.AutoIndexEnqueuerConfig.Validate())
42-
return errs.ErrorOrNil()
42+
return errs
4343
}

0 commit comments

Comments
 (0)