errors

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2017 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Example (LoggingInvalidLevel)

Example_loggingInvalidLevel tests the output for a logging error where and an invalid log level has been provided

// when the 'error' module is set to anything but debug, the callstack will
// not be appended to the error message
flogging.SetModuleLevel("error", "warning")

err := ErrorWithCallstack("Logging", "InvalidLevel", "Invalid log level provided - %s", "invalid")

if err != nil {
	fmt.Printf("%s\n", err.Error())
	fmt.Printf("%s\n", err.GetErrorCode())
	fmt.Printf("%s\n", err.GetComponentCode())
	fmt.Printf("%s\n", err.GetReasonCode())
	fmt.Printf("%s\n", err.Message())
	
Output:
LOGGING_INVALIDLEVEL - Invalid log level provided - invalid
LOGGING_INVALIDLEVEL
LOGGING
INVALIDLEVEL
LOGGING_INVALIDLEVEL - Invalid log level provided - invalid
Example (UtilityErrorWithArg)

ExampleErrorWithArg tests the output for a sample error with a message argument

// when the 'error' module is set to anything but debug, the callstack will
// not be appended to the error message
flogging.SetModuleLevel("error", "warning")

err := ErrorWithCallstack("Utility", "ErrorWithArg", "An error occurred: %s", "arg1")

if err != nil {
	fmt.Printf("%s\n", err.Error())
	fmt.Printf("%s\n", err.GetErrorCode())
	fmt.Printf("%s\n", err.GetComponentCode())
	fmt.Printf("%s\n", err.GetReasonCode())
	fmt.Printf("%s\n", err.Message())
	
Output:
UTILITY_ERRORWITHARG - An error occurred: arg1
UTILITY_ERRORWITHARG
UTILITY
ERRORWITHARG
UTILITY_ERRORWITHARG - An error occurred: arg1

Index

Examples

Constants

View Source
const MaxCallStackLength = 30

MaxCallStackLength is the maximum length of the stored call stack

Variables

This section is empty.

Functions

This section is empty.

Types

type CallStackError

type CallStackError interface {
	error
	GetStack() string
	GetErrorCode() string
	GetComponentCode() string
	GetReasonCode() string
	Message() string
}

CallStackError is a general interface for Fabric errors

func Error

func Error(componentcode string, reasoncode string, message string, args ...interface{}) CallStackError

Error creates a CallStackError using a specific Component Code and Reason Code (no callstack is recorded)

Example
// when the 'error' module is set to anything but debug, the callstack will
// not be appended to the error message
flogging.SetModuleLevel("error", "warning")

err := Error("Utility", "UnknownError", "An unknown error occurred.")

if err != nil {
	fmt.Printf("%s\n", err.Error())
	fmt.Printf("%s\n", err.GetErrorCode())
	fmt.Printf("%s\n", err.GetComponentCode())
	fmt.Printf("%s\n", err.GetReasonCode())
	fmt.Printf("%s\n", err.Message())
	
Output:
UTILITY_UNKNOWNERROR - An unknown error occurred.
UTILITY_UNKNOWNERROR
UTILITY
UNKNOWNERROR
UTILITY_UNKNOWNERROR - An unknown error occurred.
Example (BlankParameters)
// when the 'error' module is set to anything but debug, the callstack will
// not be appended to the error message
flogging.SetModuleLevel("error", "warning")

// create error with blank strings for the component code, reason code, and
// message text. the code should use the default for each value instead of
// using the blank strings
err := Error("", "", "")

if err != nil {
	fmt.Printf("%s\n", err.Error())
	fmt.Printf("%s\n", err.GetErrorCode())
	fmt.Printf("%s\n", err.GetComponentCode())
	fmt.Printf("%s\n", err.GetReasonCode())
	fmt.Printf("%s\n", err.Message())
	
Output:
UTILITY_UNKNOWNERROR - An unknown error occurred.
UTILITY_UNKNOWNERROR
UTILITY
UNKNOWNERROR
UTILITY_UNKNOWNERROR - An unknown error occurred.

func ErrorWithCallstack

func ErrorWithCallstack(componentcode string, reasoncode string, message string, args ...interface{}) CallStackError

ErrorWithCallstack creates a CallStackError using a specific Component Code and Reason Code and fills its callstack

Example
// when the 'error' module is set to anything but debug, the callstack will
// not be appended to the error message
flogging.SetModuleLevel("error", "warning")

err := ErrorWithCallstack("Utility", "UnknownError", "An unknown error occurred.")

if err != nil {
	fmt.Printf("%s\n", err.Error())
	fmt.Printf("%s\n", err.GetErrorCode())
	fmt.Printf("%s\n", err.GetComponentCode())
	fmt.Printf("%s\n", err.GetReasonCode())
	fmt.Printf("%s\n", err.Message())
	
Output:
UTILITY_UNKNOWNERROR - An unknown error occurred.
UTILITY_UNKNOWNERROR
UTILITY
UNKNOWNERROR
UTILITY_UNKNOWNERROR - An unknown error occurred.

Jump to

Keyboard shortcuts

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