package exceptions import ( "electricity_bill_calc/excel" "fmt" ) type BatchError struct { Errs []error } func NewBatchError() *BatchError { return &BatchError{Errs: make([]error, 0)} } func (e *BatchError) AddError(errs ...error) { e.Errs = append(e.Errs, errs...) } func (e BatchError) Len() int { return len(e.Errs) } func NewBatchExcelAnalysisError(errs []excel.ExcelAnalysisError) *BatchError { be := &BatchError{Errs: make([]error, 0)} for _, e := range errs { be.Errs = append(be.Errs, e) } return be } func (e BatchError) Error() string { return fmt.Sprintf("存在批量错误,共 %d 个", len(e.Errs)) }