mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
30 lines
580 B
Go
30 lines
580 B
Go
package multi
|
|
|
|
import "fmt"
|
|
|
|
// MultiError is returned by batch operations when there are errors with
|
|
// particular elements. Errors will be in a one-to-one correspondence with the
|
|
// input elements; successful elements will have a nil entry.
|
|
type MultiError []error
|
|
|
|
func (m MultiError) Error() string {
|
|
s, n := "", 0
|
|
for _, e := range m {
|
|
if e != nil {
|
|
if n == 0 {
|
|
s = e.Error()
|
|
}
|
|
n++
|
|
}
|
|
}
|
|
switch n {
|
|
case 0:
|
|
return "(0 errors)"
|
|
case 1:
|
|
return s
|
|
case 2:
|
|
return s + " (and 1 other error)"
|
|
}
|
|
return fmt.Sprintf("%s (and %d other errors)", s, n-1)
|
|
}
|