gfsperrors

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCodeSpace defines the default code space for not predefined error.
	DefaultCodeSpace = "GfSp"
	// DefaultInnerCode defines the default inner code for not predefined error.
	DefaultInnerCode = 999999
)

Variables

View Source
var (
	ErrInvalidLengthError        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowError          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupError = fmt.Errorf("proto: unexpected end of group")
)

Functions

This section is empty.

Types

type GfSpError added in v0.2.4

type GfSpError struct {
	CodeSpace      string `protobuf:"bytes,1,opt,name=code_space,json=codeSpace,proto3" json:"code_space,omitempty"`
	HttpStatusCode int32  `protobuf:"varint,2,opt,name=http_status_code,json=httpStatusCode,proto3" json:"http_status_code,omitempty"`
	InnerCode      int32  `protobuf:"varint,3,opt,name=inner_code,json=innerCode,proto3" json:"inner_code,omitempty"`
	Description    string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"`
}

func GfSpErrorList added in v0.2.4

func GfSpErrorList() []*GfSpError

GfSpErrorList returns the list of predefined errors, it is useful for query all predefined errors detailed info. Example:

list the errors by cli... etc. tools under troubleshooting.

func MakeGfSpError added in v0.2.4

func MakeGfSpError(err error) *GfSpError

MakeGfSpError returns an GfSpError from the build-in error interface. It is difficult to predefine all errors. For undefined errors, there needs to be a way to capture them and return them to the client according to the GfSpError format specified by the system. Of course, this is a guaranteed solution, the error should be well-defined is the most ideal.

If the input is not the GfSpError type, will use the DefaultCodeSpace and DefaultInnerCode, they are predefined by the reversed value, do not conflict with other predefined errors.

func Register added in v0.2.4

func Register(codeSpace string, httpStatuesCode int, innerCode int, description string) *GfSpError

Register the predefined an error to the global error manager. Every error that needs to be displayed to the client needs to meet the format of GfSpError and be pre-defined in advance.

func (*GfSpError) Descriptor added in v0.2.4

func (*GfSpError) Descriptor() ([]byte, []int)

func (*GfSpError) Error added in v0.2.4

func (m *GfSpError) Error() string

Error implements the error interface for compatibility with built-in error.

func (*GfSpError) GetCodeSpace added in v0.2.4

func (m *GfSpError) GetCodeSpace() string

func (*GfSpError) GetDescription added in v0.2.4

func (m *GfSpError) GetDescription() string

func (*GfSpError) GetHttpStatusCode added in v0.2.4

func (m *GfSpError) GetHttpStatusCode() int32

func (*GfSpError) GetInnerCode added in v0.2.4

func (m *GfSpError) GetInnerCode() int32

func (*GfSpError) Marshal added in v0.2.4

func (m *GfSpError) Marshal() (dAtA []byte, err error)

func (*GfSpError) MarshalTo added in v0.2.4

func (m *GfSpError) MarshalTo(dAtA []byte) (int, error)

func (*GfSpError) MarshalToSizedBuffer added in v0.2.4

func (m *GfSpError) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*GfSpError) ProtoMessage added in v0.2.4

func (*GfSpError) ProtoMessage()

func (*GfSpError) Reset added in v0.2.4

func (m *GfSpError) Reset()

func (*GfSpError) SetError added in v0.2.4

func (m *GfSpError) SetError(err error)

SetError sets the Description field by Error(), it is use for change the predefined Description. Example: fill the predefined error's Description according to client info.

func (*GfSpError) Size added in v0.2.4

func (m *GfSpError) Size() (n int)

func (*GfSpError) String added in v0.2.4

func (m *GfSpError) String() string

func (*GfSpError) Unmarshal added in v0.2.4

func (m *GfSpError) Unmarshal(dAtA []byte) error

func (*GfSpError) XXX_DiscardUnknown added in v0.2.4

func (m *GfSpError) XXX_DiscardUnknown()

func (*GfSpError) XXX_Marshal added in v0.2.4

func (m *GfSpError) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GfSpError) XXX_Merge added in v0.2.4

func (m *GfSpError) XXX_Merge(src proto.Message)

func (*GfSpError) XXX_Size added in v0.2.4

func (m *GfSpError) XXX_Size() int

func (*GfSpError) XXX_Unmarshal added in v0.2.4

func (m *GfSpError) XXX_Unmarshal(b []byte) error

type GfSpErrorManager

type GfSpErrorManager struct {
	// contains filtered or unexported fields
}

GfSpErrorManager manages the predefined GfSpError, the GfSpError uses as the standard error format inside the SP system, it includes the CodeSpace, HttpStatusCode, InnerCode and Description fields. The HttpStatusCode uses to fill the http response header, the InnerCode and Description uses to fill the http response body if the request is failed, the CodeSpace and InnerCode uses to help developer tp quickly pinpoint the cause and location of errors.

The InnerCode detailed specifications can be found at:

"github.com/bnb-chain/greenfield-storage-provider/base/errors.md"

func (*GfSpErrorManager) AddErr

func (g *GfSpErrorManager) AddErr(err *GfSpError)

AddErr add an error to the manager, predefined errors need to ensure the uniqueness of inner error codes.

Jump to

Keyboard shortcuts

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