mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-1223] Delete unused files/packages. * [NOD-1223] Move signal and limits to the os package. * [NOD-1223] Put database and dbaccess into the db package. * [NOD-1223] Fold the logs package into the logger package. * [NOD-1223] Rename domainmessage to appmessage. * [NOD-1223] Rename to/from DomainMessage to AppMessage. * [NOD-1223] Move appmessage to the app packge. * [NOD-1223] Move protocol to the app packge. * [NOD-1223] Move the network package to the infrastructure packge. * [NOD-1223] Rename cmd to executables. * [NOD-1223] Fix go.doc in the logger package.
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package protocolerrors
|
|
|
|
import "github.com/pkg/errors"
|
|
|
|
// ProtocolError is an error that signifies a violation
|
|
// of the peer-to-peer protocol
|
|
type ProtocolError struct {
|
|
ShouldBan bool
|
|
Cause error
|
|
}
|
|
|
|
func (e *ProtocolError) Error() string {
|
|
return e.Cause.Error()
|
|
}
|
|
|
|
func (e *ProtocolError) Unwrap() error {
|
|
return e.Cause
|
|
}
|
|
|
|
// Errorf formats according to a format specifier and returns the string
|
|
// as a ProtocolError.
|
|
func Errorf(shouldBan bool, format string, args ...interface{}) error {
|
|
return &ProtocolError{
|
|
ShouldBan: shouldBan,
|
|
Cause: errors.Errorf(format, args...),
|
|
}
|
|
}
|
|
|
|
// New returns a ProtocolError with the supplied message.
|
|
// New also records the stack trace at the point it was called.
|
|
func New(shouldBan bool, message string) error {
|
|
return &ProtocolError{
|
|
ShouldBan: shouldBan,
|
|
Cause: errors.New(message),
|
|
}
|
|
}
|
|
|
|
// Wrap wraps the given error and returns it as a ProtocolError.
|
|
func Wrap(shouldBan bool, err error, message string) error {
|
|
return &ProtocolError{
|
|
ShouldBan: shouldBan,
|
|
Cause: errors.Wrap(err, message),
|
|
}
|
|
}
|
|
|
|
// Wrapf wraps the given error with the given format and returns it as a ProtocolError.
|
|
func Wrapf(shouldBan bool, err error, format string, args ...interface{}) error {
|
|
return &ProtocolError{
|
|
ShouldBan: shouldBan,
|
|
Cause: errors.Wrapf(err, format, args...),
|
|
}
|
|
}
|