app

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2023 License: Apache-2.0 Imports: 3 Imported by: 2

README

errors

Go License codecov Made by Aleksei Burmistrov

Usage

This repository contains common components for building applications. The code in this repository is not intended for direct use in other packages. If you want to use something, then copy and paste what you need directly to your app.

Download releases

https://github.com/MrEhbr/app/releases

License

© 2022 [Aleksei Burmistrov]

Licensed under the Apache License, Version 2.0 (LICENSE). See the COPYRIGHT file for more details.

SPDX-License-Identifier: Apache-2.0

Documentation

Index

Constants

View Source
const (
	// ECONFLICT Action cannot be performed.
	ECONFLICT errorCode = "conflict"
	// EINTERNAL internal error.
	EINTERNAL errorCode = "internal"
	// EINVALID validation failed.
	EINVALID errorCode = "invalid"
	// ENOTFOUND entity not found/doesn't exist.
	ENOTFOUND errorCode = "not_found"
	// ENOTMODIFIED entity not modified.
	ENOTMODIFIED errorCode = "not_modified"
	// EALREADYEXISTS entity already exists.
	EALREADYEXISTS errorCode = "already_exists"
	// EPermissionDenied user does not have permission.
	EPERMISSIONDENIED errorCode = "permission_denied"
	// EUNAUTHENTICATED Requestor does not have valid authentication to perform to operation.
	EUNAUTHENTICATED errorCode = "unauthenticated"
	// ECANNOTDECODE Data could not be decoded.
	ECANNOTDECODE errorCode = "cannot_decode"
	// ECANNOTENCODE Data could not be encoded.
	ECANNOTENCODE errorCode = "cannot_encode"
	// ECANNOTPARSE Data could not be parsed.
	ECANNOTPARSE errorCode = "cannot_parse"
	// EBEHAVIOUR something that must not be.
	EBEHAVIOUR errorCode = "undefined_behavior"
	// EUNSUPPORTED means that we dont support some actions
	// and this actions should be handled by others.
	EUNSUPPORTED errorCode = "unsupported"
	// ETEST test error code, useful for testing.
	ETEST errorCode = "test_error_code"

	DefaultErrorMessage = "An internal error has occurred"
)

Application error codes.

Variables

This section is empty.

Functions

func CallerFunctionName

func CallerFunctionName() string

func CurrentFunctionName

func CurrentFunctionName() string

func ErrorCode

func ErrorCode(err error) errorCode

ErrorCode returns the code of the error, if available. Otherwise returns EINTERNAL.

func ErrorFields

func ErrorFields(err error) map[string]interface{}

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage returns the human-readable message of the error, if available. Otherwise returns a generic error message.

func ErrorMessageDefault

func ErrorMessageDefault(err error, def string) string

ErrorMessage returns the human-readable message of the error, if available. Otherwise returns default message if default is not empty, otherwise return err.Error().

func ErrorTrace

func ErrorTrace(err error) []string

func ErrorWithCode

func ErrorWithCode(err error, code errorCode) error

ErrorWithCode adds an error code to the provided error. If Error.Op is undefined, caller function name will be used as Op If the err is an Error && err.Code is undefined, the code is applied to the Error; If the err is an Error && err.Code is defined, the err is wrapped and the code is applied; If the err is a regular error, the error is wrapped and the code is applied.

func OpError

func OpError(op string, err error) error

func OpErrorOrNil

func OpErrorOrNil(op string, err error) error

Types

type Error

type Error struct {
	// Wrapped error
	Err error `json:"err"`
	// Some context of error
	Fields map[string]interface{}
	// Machine-readable error code.
	Code errorCode `json:"code"`
	// Human-readable message.
	Message string `json:"message"`
	// Logical operation.
	Op string `json:"op"`
}

Error defines a standard application error.

func (*Error) Error

func (e *Error) Error() string

Error returns the string representation of the error message.

func (*Error) Is

func (e *Error) Is(err error) bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

Directories

Path Synopsis
log
zap module
zerolog module

Jump to

Keyboard shortcuts

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