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: https://granitic.io/ref/service-error-management the package documentation for facility/serviceerror gives a brief example of how to define errors in your application.
Index ¶
- type ErrorCodeUser
- type ServiceErrorManager
- func (sem *ServiceErrorManager) AllowAccess() error
- func (sem *ServiceErrorManager) ComponentName() string
- func (sem *ServiceErrorManager) Find(code string) *ws.CategorisedError
- func (sem *ServiceErrorManager) LoadErrors(definitions []interface{})
- func (sem *ServiceErrorManager) RegisterCodeUser(ecu ErrorCodeUser)
- func (sem *ServiceErrorManager) SetComponentName(name string)
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 }
ErrorCodeUser is 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 }
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
ComponentName implements 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)
SetComponentName ioc.ComponentNamer.SetComponentName