errors

package
v0.0.0-...-d983439 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GrpcError

func GrpcError(code codes.Code, message string) error

NewGrpcErrorWithMessage creates and/or transforms a provided error into a gRPC error

func GrpcErrorFromErr

func GrpcErrorFromErr(code codes.Code, err error) error

NewGrpcErrorWithErr creates and/or transforms a provided error into a gRPC error

If the provided `Error` is a known Error within this package we will leverage its details to convert it into a GrpcError. If it is not, we will call directly the method `Error()` that will return a `string` that we will use as the Standard Error Message.

func GrpcErrorf

func GrpcErrorf(c codes.Code, format string, a ...interface{}) error

NewGrpcErrorWithMessagef creates and/or transforms a provided error into a gRPC error

Types

type BackendError

type BackendError struct {
	*StandardError
}

BackendError type

Whenever there is an error in the Backend, use this error handler to standardize all errors reported to the users and/or logging to the systems log

Example: ```

statusResult, found := searchResult.Aggregations.Terms("status_counts")
if !found {
  return errors.NewBackendError("Aggregation term 'status_counts' not found")
}

```

func NewBackendError

func NewBackendError(format string, args ...interface{}) *BackendError

NewBackendError - create a new backend error

type ErrorType

type ErrorType int

ErrorType will be our enum to identity types of errors

const (
	GrpcClient ErrorType = iota
	Backend
	InvalidParameter
	NodeNotFound
	NodeAttributeNotFound
	RunNotFound
	PolicyCookbooksNotFound
)

Add multiple error types that will be associated with an integer, then make sure to update the `typeString` map below to do the translation to String

type StandardError

type StandardError struct {
	Type    ErrorType `json:"-"` // Avoid displaying the type to the user
	Message string    `json:"message"`
}

StandardError type

For any standard error (that is not either a RestClient nor a Backend), use this error handler to standardize all errors reported to the users and/or logging to the systems log

Example: When there is an invalid `filter` parameter ```

errors.New(
  errors.InvalidParameter,
  fmt.Sprintf("Invalid filter '%s' (format: key:value)", filter),
)

```

func New

func New(eType ErrorType, msg string) *StandardError

New creates a new StandardError struct

func (StandardError) Error

func (e StandardError) Error() string

Implementation of the `Error` interface

func (StandardError) ToJSON

func (e StandardError) ToJSON() ([]byte, error)

ToJSON converts the StandardError into JSON format

func (StandardError) ToString

func (e StandardError) ToString() string

ToString converts the StandardError into String format

func (StandardError) TypeString

func (e StandardError) TypeString() string

TypeString converts our enum ErrorType into a readable string

Jump to

Keyboard shortcuts

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