errs

package
v0.6.18 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(code ErrorCode, args ...interface{}) error

Errorf create standard error from code

func GetCode

func GetCode(err error) codes.Code

GetCode returns the error's code

func GetValue added in v0.6.14

func GetValue(err error, key string) any

GetValue returns the first key-matched value found in the error details, or nil.

Example
package main

import (
	"fmt"
	"io"

	"gitlab.com/picnic-app/backend/libs/golang/core/errs"
)

func main() {
	err := io.EOF
	err = errs.WithValue(err, "key", "value")

	fmt.Println(errs.GetValue(err, "key"))

}
Output:

value

func GetValues added in v0.6.14

func GetValues(err error) map[string]any

GetValues returns all details stored in the error.

Example
package main

import (
	"fmt"
	"io"

	"gitlab.com/picnic-app/backend/libs/golang/core/errs"
)

func main() {
	err := io.EOF
	err = errs.WithValue(err, "key1", "value")
	err = errs.WithValue(err, "key2", 1)
	err = errs.WithValue(err, "key2", 2)
	err = errs.WithValue(err, "key2", 3)

	fmt.Println(errs.GetValues(err))

}
Output:

map[key1:value key2:[1 2 3]]

func WithValue added in v0.6.14

func WithValue(err error, key string, value any) error

WithValue returns error storing the value for the specified key.

Example
package main

import (
	"io"

	"gitlab.com/picnic-app/backend/libs/golang/core/errs"
)

func main() {
	err := io.EOF
	_ = errs.WithValue(err, "some_key", "some_value")
}
Example (Nil)
package main

import (
	"gitlab.com/picnic-app/backend/libs/golang/core/errs"
)

func main() {
	_ = errs.WithValue(nil, "some_key", "some_value")
}

Types

type ErrorCode

type ErrorCode uint32

ErrorCode ..

const (
	CodeUnknown ErrorCode = iota
	CodeUnauthenticated
	CodeDBNotFound
	CodeInternalError
)

..

Jump to

Keyboard shortcuts

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