xerrors

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2019 License: MIT Imports: 4 Imported by: 0

README

Documentation

Overview

Package xerrors implements like "golang.org/x/errors" package.

This package have Helper function, and if calling Helper, got a stacktrace will skipping it function.

This package difference to "golang.org/x/errors" package is error wrapping style. Original package is using printf style ( e.g. ": %w" ) however this package using Wrap function.

Simply Example:

    package main

    import (
	       "fmt"

	       "go.nanasi880.dev/xerrors"
    )

    func main() {
	       err := newError()

	       fmt.Printf("%v\n", err)
	       // Output:
	       // fail

	       fmt.Printf("%+v\n", err)
	       // Output:
	       // fail
	       //     mypackage/main.newError
	       //         /Users/myname/project/main.go:23
    }

    func newError() error {
	       return xerrors.New("fail").Build()
    }

Helper Example:

package main

import (
     "fmt"

      "go.nanasi880.dev/xerrors"
 )

 func main() {
      err := newError()

      fmt.Printf("%v\n", err)
      // Output:
      // fail

      fmt.Printf("%+v\n", err)
      // Output:
      // fail
      //     mypackage/main.main
      //         /Users/myname/project/main.go:10
 }

 func newError() error {
      xerrors.Helper() // this function is Helper. do not logging stacktrace.
      return xerrors.New("fail").Build()
 }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

https://godoc.org/golang.org/x/xerrors#As

func Helper

func Helper()

Helper is marking the caller function as helper function. New and Errorf function is skipping the helper function.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is error builder

func Errorf

func Errorf(format string, args ...interface{}) *Builder

Errorf is create error builder with format string.

func New

func New(s string) *Builder

New is create error builder with plain test message.

func (*Builder) Build

func (e *Builder) Build() error

Build is building error.

func (*Builder) Wrap

func (e *Builder) Wrap(err error) *Builder

Wrap is wrapping base error. builder can have one error object.

Jump to

Keyboard shortcuts

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