Documentation
¶
Overview ¶
Package multierror can be leveraged as an opinionated to handle multiple errors providing appropriate wrapping for them.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FormatFunc ¶
FormatFunc defines a format function which should format a slice of errors into a string.
type Prefixed ¶
type Prefixed struct {
Prefix string
Errors []error
FormatFunc FormatFunc
}
Prefixed is a multierror which will prefix the error output message with the specified prefix.
Example ¶
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package main
import (
"errors"
"fmt"
"io"
"os"
)
var output io.Writer = os.Stdout
func main() {
err := NewPrefixed("config validation")
err = err.Append(errors.New("some validation error"))
if err.ErrorOrNil() != nil {
fmt.Fprintln(output, err)
}
}
func NewPrefixed ¶
NewPrefixed creates a new pointer to Prefixed w
func (*Prefixed) Append ¶
Append appends a number of errors to the current instance of Prefixed. It'll unwrap any wrapped errors in the form of *Prefixed or *multierror.Error.
func (*Prefixed) Error ¶
Error returns the stored slice of error formatted using a set FormatFunc or multierror.ListFormatFunc when no FormatFunc is specified.
func (*Prefixed) ErrorOrNil ¶
ErrorOrNil either returns nil when the type is nil or when there's no Errors. Otherwise, the type is returned.