diff options
Diffstat (limited to 'internal/pkg/pkg.go')
| -rw-r--r-- | internal/pkg/pkg.go | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go index 99772c8f..76bae916 100644 --- a/internal/pkg/pkg.go +++ b/internal/pkg/pkg.go @@ -1188,39 +1188,38 @@ func (e *CureError) Error() string { return e.Err.Error() } // A DependencyCureError wraps errors returned while curing dependencies. type DependencyCureError []*CureError -// sort sorts underlying errors by their identifier. -func (e *DependencyCureError) sort() { - var identBuf [2]ID - slices.SortFunc(*e, func(a, b *CureError) int { - identBuf[0], identBuf[1] = a.Ident.Value(), b.Ident.Value() - return slices.Compare(identBuf[0][:], identBuf[1][:]) - }) -} - -// unwrap recursively expands and deduplicates underlying errors. -func (e *DependencyCureError) unwrap() DependencyCureError { - errs := make(DependencyCureError, 0, len(*e)) +// unwrapM recursively expands underlying errors into a caller-supplied map. +func (e *DependencyCureError) unwrapM(me map[unique.Handle[ID]]*CureError) { for _, err := range *e { if _e, ok := err.Err.(*DependencyCureError); ok { - errs = append(errs, _e.unwrap()...) + _e.unwrapM(me) continue } - errs = append(errs, err) - } - me := make(map[unique.Handle[ID]]*CureError, len(errs)) - for _, err := range errs { me[err.Ident] = err } - return slices.AppendSeq( +} + +// unwrap recursively expands and deduplicates underlying errors. +func (e *DependencyCureError) unwrap() DependencyCureError { + me := make(map[unique.Handle[ID]]*CureError) + e.unwrapM(me) + errs := slices.AppendSeq( make(DependencyCureError, 0, len(me)), maps.Values(me), ) + + var identBuf [2]ID + slices.SortFunc(errs, func(a, b *CureError) int { + identBuf[0], identBuf[1] = a.Ident.Value(), b.Ident.Value() + return slices.Compare(identBuf[0][:], identBuf[1][:]) + }) + + return errs } // Unwrap returns a deduplicated slice of underlying errors. func (e *DependencyCureError) Unwrap() []error { errs := e.unwrap() - errs.sort() _errs := make([]error, len(errs)) for i, err := range errs { _errs[i] = err @@ -1231,7 +1230,6 @@ func (e *DependencyCureError) Unwrap() []error { // Error returns a user-facing multiline error message. func (e *DependencyCureError) Error() string { errs := e.unwrap() - errs.sort() if len(errs) == 0 { return "invalid dependency cure outcome" } |
