1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package errorutil
- import (
- "bytes"
- )
- func AssertOk(err error) {
- if err != nil {
- panic(err.Error())
- }
- }
- func AssertTrue(condition bool, errString string) {
- if !condition {
- panic(errString)
- }
- }
- type CompositeError struct {
- Errors []error
- }
- func NewCompositeError() *CompositeError {
- return &CompositeError{make([]error, 0)}
- }
- func (ce *CompositeError) Add(e error) {
- ce.Errors = append(ce.Errors, e)
- }
- func (ce *CompositeError) HasErrors() bool {
- return len(ce.Errors) > 0
- }
- func (ce *CompositeError) Error() string {
- var buf bytes.Buffer
- for i, e := range ce.Errors {
- buf.WriteString(e.Error())
- if i < len(ce.Errors)-1 {
- buf.WriteString("; ")
- }
- }
- return buf.String()
- }
|