Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

combinederr.gno

0.67 Kb · 40 lines
 1package combinederr
 2
 3import "strings"
 4
 5// CombinedError is a combined execution error
 6type CombinedError struct {
 7	errors []error
 8}
 9
10// Error returns the combined execution error
11func (e *CombinedError) Error() string {
12	if len(e.errors) == 0 {
13		return ""
14	}
15
16	var sb strings.Builder
17
18	for _, err := range e.errors {
19		sb.WriteString(err.Error() + "; ")
20	}
21
22	// Remove the last semicolon and space
23	result := sb.String()
24
25	return result[:len(result)-2]
26}
27
28// Add adds a new error to the execution error
29func (e *CombinedError) Add(err error) {
30	if err == nil {
31		return
32	}
33
34	e.errors = append(e.errors, err)
35}
36
37// Size returns a
38func (e *CombinedError) Size() int {
39	return len(e.errors)
40}