Categorygithub.com/golage/errors
modulepackage
1.2.1
Repository: https://github.com/golage/errors.git
Documentation: pkg.go.dev

# README

Golage errors handling https://github.com/golage/errors https://github.com/golage/errors https://github.com/golage/errors

Simple and useful error handling package in Golang

Features

  • Fundamental
  • Support stacktrace
  • Wrap existing errors
  • Easy and pretty error handling
  • Support serialization (for transports in grpc, api, etc...)
  • Support stacktrace errors in github.com/pkg/errors
  • Handling error types with code numbers (you can extends with constants)

Installation

Get from Github:

go get github.com/golage/errors

How to use

Import into your code:

import "github.com/golage/errors"

Create error instance:

errors.New(errors.CodeNotFound, "somethings")
errors.New(errors.CodeNotFound, "somethings %v", 123)

Wrap existing error:

errors.Wrap(err, errors.CodeInternal, "somethings")
errors.Wrap(err, errors.CodeInternal, "somethings %v", 123)

Handle error:

switch err, code := errors.Parse(err); code {
case errors.CodeNil:
case errors.CodeNotFound:
    log.Fatalf("not found: %v", err)
default:
    log.Fatalf("others: %v\n%v", err, err.StackTrace())
}

For more see example

# Packages

No description provided by the author
Package stacktrace is implements for capture errors stacktrace.

# Functions

Cast returns new instance fundamental error with error cause and code.
New returns new instance fundamental error with args.
Parse returns fundamental error and code from all of error types.
Wrap returns new instance fundamental error with args from error cause.

# Constants

CodeAlreadyExists means there is same data is already exists.
CodeInternal means internal module returns error.
CodeInvalidData means input parameters are invalid.
CodeNil means no error exists.
CodeNotFound means there is no data found.
CodePermissionDenied means user does not have access permissions.
CodeUnauthenticated means user does not authenticated.
CodeUnimplemented means code does not implemented.
CodeUnknown means unknown error raised.

# Interfaces

Fundamental interface of fundamental error.

# Type aliases

Code implements error code number, you can extends this with define constants with this type.