errs

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func String

func String(prefix interface{}, values map[string]interface{}, wrapped error) string

String will generate an error string that conforms to our error coding style. This will:

  • Print the name of the error struct
  • Enclose any key sorted values within parenthesis
  • Append any wrapped errors to the end of the message (separated by a ":")
Example
package main

import (
	"fmt"

	"github.com/xmidt-org/ears/pkg/errs"
)

type MyError struct {
	Message string
	Code    int
	Err     error
}

func (e *MyError) Error() string {
	return errs.String(
		"MyError",
		map[string]interface{}{
			"msg":  e.Message,
			"code": e.Code,
		},
		e.Err,
	)
}

func main() {

	e := &MyError{
		Message: "couldn't compute the meaning of life",
		Code:    -42,
		Err:     fmt.Errorf("observation collapsed the function too hard"),
	}

	fmt.Println(e)
}
Output:

MyError (code=-42 msg=couldn't compute the meaning of life): observation collapsed the function too hard

func Type

func Type(err error) string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL