grncerror

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2019 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorCodeUser

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

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

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

func (sem *ServiceErrorManager) ComponentName() string

See ioc.ComponentNamer.ComponentName

func (*ServiceErrorManager) Find

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

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

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

func (sem *ServiceErrorManager) SetComponentName(name string)

See ioc.ComponentNamer.SetComponentName

Jump to

Keyboard shortcuts

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