granitic: github.com/graniticio/granitic/grncerror Index | Files

package grncerror

import "github.com/graniticio/granitic/grncerror"

Package grncerror defines error-message management types and error handling functions.

The primary type in this package is ServiceErrorManager, which allows an application to manage error definitions (messages and categories) in a single location and have them looked up and referred to by error codes throughout the application.

A ServiceErrorManager is made available to applications by enabling the ServiceErrorManager facility. This facility is documented in detail here: http://granitic.io/1.0/ref/service-errors the package documentation for facility/serviceerror gives a brief example of how to define errors in your application.

Index

Package Files

serviceerror.go

type ErrorCodeUser Uses

type ErrorCodeUser interface {
    // ErrorCodesInUse returns the set of error codes that this component relies on and the component's name
    ErrorCodesInUse() (codes types.StringSet, component string)

    // ValidateMissing returns false if the component does not want the codes it uses checked.
    ValidateMissing() bool
}

Implemented by components that want to decare that they use error codes, so that all codes they use can be validated to make sure that they have corresponding definitions.

type ServiceErrorManager Uses

type ServiceErrorManager struct {

    // Logger used by Granitic framework components. Automatically injected.
    FrameworkLogger logging.Logger

    // Determines whether or not a panic should be triggered if a method on this type is called with
    // an error code that is not stored in the map of codes to errors.
    PanicOnMissing bool
    // contains filtered or unexported fields
}

An instance of ServiceErrorManager contains a map between an error code and a ws.CategorisedError.

func (*ServiceErrorManager) AllowAccess Uses

func (sem *ServiceErrorManager) AllowAccess() error

AllowAccess is called by the IoC container after all components have been configured and started. At this point all of the error codes that have been declared to be in use can be compared with the available error code definitions.

If there are any codes that are in use, but do not have a corresponding error definition an error will be returned.

func (*ServiceErrorManager) ComponentName Uses

func (sem *ServiceErrorManager) ComponentName() string

See ioc.ComponentNamer.ComponentName

func (*ServiceErrorManager) Find Uses

func (sem *ServiceErrorManager) Find(code string) *ws.CategorisedError

Find returns the CategorisedError associated with the supplied code. If the code does not exist and PanicOnMissing is false, nil is returned. If PanicOnMissing is true the goroutine panics.

func (*ServiceErrorManager) LoadErrors Uses

func (sem *ServiceErrorManager) LoadErrors(definitions []interface{})

LoadErrors parses error definitions from the supplied definitions which will be cast from []interface to [][]string Each element of the sub-array is expected to be a []string with three elements.

func (*ServiceErrorManager) RegisterCodeUser Uses

func (sem *ServiceErrorManager) RegisterCodeUser(ecu ErrorCodeUser)

RegisterCodeUser accepts a reference to a component ErrorCodeUser so that the set of error codes actually in use can be monitored.

func (*ServiceErrorManager) SetComponentName Uses

func (sem *ServiceErrorManager) SetComponentName(name string)

See ioc.ComponentNamer.SetComponentName

Package grncerror imports 7 packages (graph) and is imported by 2 packages. Updated 2016-10-26. Refresh now. Tools for package owners.