Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/Make errors return default messages #369

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions client/status/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,17 @@ type SignatureVerification struct {
v2 status.Status
}

const defaultSignatureVerificationMsg = "signature verification failed"

func (x SignatureVerification) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultSignatureVerificationMsg
}

return errMessageStatusV2(
globalizeCodeV2(status.SignatureVerificationFail, status.GlobalizeCommonFail),
x.v2.Message(),
msg,
)
}

Expand All @@ -153,7 +160,7 @@ func (x SignatureVerification) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(status.SignatureVerificationFail, status.GlobalizeCommonFail))

if x.v2.Message() == "" {
x.v2.SetMessage("signature verification failed")
x.v2.SetMessage(defaultSignatureVerificationMsg)
}

return &x.v2
Expand Down Expand Up @@ -181,11 +188,13 @@ type NodeUnderMaintenance struct {
v2 status.Status
}

const defaultNodeUnderMaintenanceMsg = "node is under maintenance"

// Error implements the error interface.
func (x NodeUnderMaintenance) Error() string {
msg := x.Message()
if msg == "" {
msg = "node is under maintenance"
msg = defaultNodeUnderMaintenanceMsg
}

return errMessageStatusV2(
Expand All @@ -202,10 +211,15 @@ func (x *NodeUnderMaintenance) fromStatusV2(st *status.Status) {
// If the value was returned by FromStatusV2, returns the source message.
// Otherwise, returns message with
// - code: NODE_UNDER_MAINTENANCE;
// - string message: written message via SetMessage;
// - string message: written message via SetMessage or
// "node is under maintenance" as a default message;
// - details: empty.
func (x NodeUnderMaintenance) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(status.NodeUnderMaintenance, status.GlobalizeCommonFail))
if x.v2.Message() == "" {
x.v2.SetMessage(defaultNodeUnderMaintenanceMsg)
}

return &x.v2
}

Expand Down
22 changes: 18 additions & 4 deletions client/status/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ type ContainerNotFound struct {
v2 status.Status
}

const defaultContainerNotFoundMsg = "container not found"

func (x ContainerNotFound) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultContainerNotFoundMsg
}

return errMessageStatusV2(
globalizeCodeV2(container.StatusNotFound, container.GlobalizeFail),
x.v2.Message(),
msg,
)
}

Expand All @@ -31,7 +38,7 @@ func (x *ContainerNotFound) fromStatusV2(st *status.Status) {
// - details: empty.
func (x ContainerNotFound) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(container.StatusNotFound, container.GlobalizeFail))
x.v2.SetMessage("container not found")
x.v2.SetMessage(defaultContainerNotFoundMsg)
return &x.v2
}

Expand All @@ -42,10 +49,17 @@ type EACLNotFound struct {
v2 status.Status
}

const defaultEACLNotFoundMsg = "eACL not found"

func (x EACLNotFound) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultEACLNotFoundMsg
}

return errMessageStatusV2(
globalizeCodeV2(container.StatusEACLNotFound, container.GlobalizeFail),
x.v2.Message(),
msg,
)
}

Expand All @@ -62,6 +76,6 @@ func (x *EACLNotFound) fromStatusV2(st *status.Status) {
// - details: empty.
func (x EACLNotFound) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(container.StatusEACLNotFound, container.GlobalizeFail))
x.v2.SetMessage("eACL not found")
x.v2.SetMessage(defaultEACLNotFoundMsg)
return &x.v2
}
66 changes: 54 additions & 12 deletions client/status/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ type ObjectLocked struct {
v2 status.Status
}

const defaultObjectLockedMsg = "object is locked"

func (x ObjectLocked) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultObjectLockedMsg
}

return errMessageStatusV2(
globalizeCodeV2(object.StatusLocked, object.GlobalizeFail),
x.v2.Message(),
msg,
)
}

Expand All @@ -31,7 +38,7 @@ func (x *ObjectLocked) fromStatusV2(st *status.Status) {
// - details: empty.
func (x ObjectLocked) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(object.StatusLocked, object.GlobalizeFail))
x.v2.SetMessage("object is locked")
x.v2.SetMessage(defaultObjectLockedMsg)
return &x.v2
}

Expand All @@ -41,10 +48,17 @@ type LockNonRegularObject struct {
v2 status.Status
}

const defaultLockNonRegularObjectMsg = "locking non-regular object is forbidden"

func (x LockNonRegularObject) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultLockNonRegularObjectMsg
}

return errMessageStatusV2(
globalizeCodeV2(object.StatusLockNonRegularObject, object.GlobalizeFail),
x.v2.Message(),
msg,
)
}

Expand All @@ -61,7 +75,7 @@ func (x *LockNonRegularObject) fromStatusV2(st *status.Status) {
// - details: empty.
func (x LockNonRegularObject) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(object.StatusLockNonRegularObject, object.GlobalizeFail))
x.v2.SetMessage("locking non-regular object is forbidden")
x.v2.SetMessage(defaultLockNonRegularObjectMsg)
return &x.v2
}

Expand All @@ -71,10 +85,17 @@ type ObjectAccessDenied struct {
v2 status.Status
}

const defaultObjectAccessDeniedMsg = "access to object operation denied"

func (x ObjectAccessDenied) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultObjectAccessDeniedMsg
}

return errMessageStatusV2(
globalizeCodeV2(object.StatusAccessDenied, object.GlobalizeFail),
x.v2.Message(),
msg,
)
}

Expand All @@ -91,7 +112,7 @@ func (x *ObjectAccessDenied) fromStatusV2(st *status.Status) {
// - details: empty.
func (x ObjectAccessDenied) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(object.StatusAccessDenied, object.GlobalizeFail))
x.v2.SetMessage("access to object operation denied")
x.v2.SetMessage(defaultObjectAccessDeniedMsg)
return &x.v2
}

Expand All @@ -112,10 +133,17 @@ type ObjectNotFound struct {
v2 status.Status
}

const defaultObjectNotFoundMsg = "object not found"

func (x ObjectNotFound) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultObjectNotFoundMsg
}

return errMessageStatusV2(
globalizeCodeV2(object.StatusNotFound, object.GlobalizeFail),
x.v2.Message(),
msg,
)
}

Expand All @@ -132,7 +160,7 @@ func (x *ObjectNotFound) fromStatusV2(st *status.Status) {
// - details: empty.
func (x ObjectNotFound) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(object.StatusNotFound, object.GlobalizeFail))
x.v2.SetMessage("object not found")
x.v2.SetMessage(defaultObjectNotFoundMsg)
return &x.v2
}

Expand All @@ -142,10 +170,17 @@ type ObjectAlreadyRemoved struct {
v2 status.Status
}

const defaultObjectAlreadyRemovedMsg = "object already removed"

func (x ObjectAlreadyRemoved) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultObjectAlreadyRemovedMsg
}

return errMessageStatusV2(
globalizeCodeV2(object.StatusAlreadyRemoved, object.GlobalizeFail),
x.v2.Message(),
msg,
)
}

Expand All @@ -162,7 +197,7 @@ func (x *ObjectAlreadyRemoved) fromStatusV2(st *status.Status) {
// - details: empty.
func (x ObjectAlreadyRemoved) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(object.StatusAlreadyRemoved, object.GlobalizeFail))
x.v2.SetMessage("object already removed")
x.v2.SetMessage(defaultObjectAlreadyRemovedMsg)
return &x.v2
}

Expand All @@ -173,10 +208,17 @@ type ObjectOutOfRange struct {
v2 status.Status
}

const defaultObjectOutOfRangeMsg = "out of range"

func (x ObjectOutOfRange) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultObjectOutOfRangeMsg
}

return errMessageStatusV2(
globalizeCodeV2(object.StatusOutOfRange, object.GlobalizeFail),
x.v2.Message(),
msg,
)
}

Expand All @@ -193,6 +235,6 @@ func (x *ObjectOutOfRange) fromStatusV2(st *status.Status) {
// - details: empty.
func (x ObjectOutOfRange) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(object.StatusOutOfRange, object.GlobalizeFail))
x.v2.SetMessage("out of range")
x.v2.SetMessage(defaultObjectOutOfRangeMsg)
return &x.v2
}
22 changes: 18 additions & 4 deletions client/status/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ type SessionTokenNotFound struct {
v2 status.Status
}

const defaultSessionTokenNotFoundMsg = "session token not found"

func (x SessionTokenNotFound) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultSessionTokenNotFoundMsg
}

return errMessageStatusV2(
globalizeCodeV2(session.StatusTokenNotFound, session.GlobalizeFail),
x.v2.Message(),
msg,
)
}

Expand All @@ -31,7 +38,7 @@ func (x *SessionTokenNotFound) fromStatusV2(st *status.Status) {
// - details: empty.
func (x SessionTokenNotFound) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(session.StatusTokenNotFound, session.GlobalizeFail))
x.v2.SetMessage("session token not found")
x.v2.SetMessage(defaultSessionTokenNotFoundMsg)
return &x.v2
}

Expand All @@ -41,10 +48,17 @@ type SessionTokenExpired struct {
v2 status.Status
}

const defaultSessionTokenExpiredMsg = "expired session token"

func (x SessionTokenExpired) Error() string {
msg := x.v2.Message()
if msg == "" {
msg = defaultSessionTokenExpiredMsg
}

return errMessageStatusV2(
globalizeCodeV2(session.StatusTokenExpired, session.GlobalizeFail),
x.v2.Message(),
msg,
)
}

Expand All @@ -61,6 +75,6 @@ func (x *SessionTokenExpired) fromStatusV2(st *status.Status) {
// - details: empty.
func (x SessionTokenExpired) ToStatusV2() *status.Status {
x.v2.SetCode(globalizeCodeV2(session.StatusTokenExpired, session.GlobalizeFail))
x.v2.SetMessage("expired session token")
x.v2.SetMessage(defaultSessionTokenExpiredMsg)
return &x.v2
}