diff --git a/go/parts/receive.go b/go/parts/receive.go index d2ac237..f745188 100644 --- a/go/parts/receive.go +++ b/go/parts/receive.go @@ -93,6 +93,13 @@ type Received struct { Ended bool } +// AtCap opens the reason of a refusal for want of room: the objects would pass their cap. A holder tells it from +// the other refusals with RefusedAtCap, so the finding it raises for it can clear once it takes a file again. +const AtCap = "the objects are at their cap" + +// RefusedAtCap says whether a refusal's reason is one for want of room (AtCap). +func RefusedAtCap(reason string) bool { return strings.HasPrefix(reason, AtCap) } + // Receiver takes transfers in parts into a holder's own objects. type Receiver[M any] struct { Objects Objects @@ -182,7 +189,7 @@ func (r *Receiver[M]) Open(id, opener string, parts []Want, shape M) (Received, size += uint64(max(p.Size, 0)) } if used+size > r.Cap { - return Received{ID: id, Ended: true}, r.refuse(t, fmt.Sprintf("the objects are at their cap of %d bytes (%d held, %d asked)", r.Cap, used, size)) + return Received{ID: id, Ended: true}, r.refuse(t, fmt.Sprintf(AtCap+" of %d bytes (%d held, %d asked)", r.Cap, used, size)) } if r.Holds != nil { for _, p := range parts { diff --git a/go/parts/receive_test.go b/go/parts/receive_test.go index 0f355bf..ac37613 100644 --- a/go/parts/receive_test.go +++ b/go/parts/receive_test.go @@ -186,6 +186,9 @@ func TestAHolderTakesAFileInParts(t *testing.T) { if got := pkgLog[len(pkgLog)-1].outcome; !strings.HasPrefix(got, "refused: the objects are at their cap") { t.Errorf("the cap's refusal said %q", got) } + if !RefusedAtCap(strings.TrimPrefix(pkgLog[len(pkgLog)-1].outcome, "refused: ")) || RefusedAtCap(strings.TrimPrefix(pkgLog[len(pkgLog)-2].outcome, "refused: ")) { + t.Errorf("RefusedAtCap tells the cap's refusal from the check's: %q, %q", pkgLog[len(pkgLog)-1].outcome, pkgLog[len(pkgLog)-2].outcome) + } if got := pkgLog[len(pkgLog)-2].outcome; got != "refused: the builder did not number it" { t.Errorf("the check's refusal said %q", got) }