aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/pkg.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pkg/pkg.go')
-rw-r--r--internal/pkg/pkg.go35
1 files changed, 27 insertions, 8 deletions
diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go
index 220f268d..268d0248 100644
--- a/internal/pkg/pkg.go
+++ b/internal/pkg/pkg.go
@@ -15,6 +15,7 @@ import (
"hash"
"io"
"io/fs"
+ "iter"
"maps"
"math"
"os"
@@ -1723,8 +1724,9 @@ retry:
// An InputError describes inputs of a [FloodArtifact] which had failed to cure.
type InputError map[Artifact]error
-// Error returns a user-facing, deterministic text representation of e.
-func (e InputError) Error() string {
+// unwrap returns an iterator over sorted, deduplicated [Artifact] and their
+// corresponding identifier.
+func (e InputError) unwrap() iter.Seq2[Artifact, unique.Handle[ID]] {
ir := NewIR()
type input struct {
@@ -1741,20 +1743,37 @@ func (e InputError) Error() string {
identBuf[0], identBuf[1] = a.id.Value(), b.id.Value()
return slices.Compare(identBuf[0][:], identBuf[1][:])
})
+ p = slices.CompactFunc(p, func(a, b input) bool { return a.id == b.id })
+ return func(yield func(Artifact, unique.Handle[ID]) bool) {
+ for _, i := range p {
+ if !yield(i.a, i.id) {
+ return
+ }
+ }
+ }
+}
+
+// Error returns a user-facing, deterministic text representation of e.
+func (e InputError) Error() string {
var buf strings.Builder
buf.WriteString("errors curing inputs:")
- for _, i := range p {
- buf.WriteString("\n\t" +
- reportName(i.a, i.id) + ": " +
- e[i.a].Error())
+ for a, id := range e.unwrap() {
+ buf.WriteString("\n\t")
+ buf.WriteString(reportName(a, id))
+ buf.WriteString(": ")
+ buf.WriteString(e[a].Error())
}
return buf.String()
}
-// Unwrap returns a slice of underlying errors in unspecified order.
+// Unwrap returns a slice of underlying errors sorted by identifier.
func (e InputError) Unwrap() []error {
- return slices.AppendSeq(make([]error, 0, len(e)), maps.Values(e))
+ errs := make([]error, 0, len(e))
+ for a := range e.unwrap() {
+ errs = append(errs, e[a])
+ }
+ return errs
}
// enterCure must be called before entering an [Artifact] implementation.