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

More verbose error in service backend #1490

Merged
merged 14 commits into from
Nov 27, 2019
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
26 changes: 26 additions & 0 deletions cosmos/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cosmos

import (
"github.com/cosmos/cosmos-sdk/types"
)

const (
// CodespaceMesg is a cosmos codespace for all mesg errors.
CodespaceMesg types.CodespaceType = "mesg"
)

// Base mesg codes.
const (
CodeInternal types.CodeType = 1000
CodeValidation types.CodeType = 2000
)

// NewMesgErrorf creates error with given code type and mesg codespace.
func NewMesgErrorf(ct types.CodeType, format string, a ...interface{}) types.Error {
return types.NewError(CodespaceMesg, ct, format, a...)
}

// NewMesgWrapError creates error with given code type and mesg codespace.
func NewMesgWrapError(ct types.CodeType, err error) types.Error {
return types.NewError(CodespaceMesg, ct, err.Error())
}
4 changes: 2 additions & 2 deletions cosmos/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ func (m AppModule) NewQuerierHandler() cosmostypes.Querier {
if errsdk, ok := err.(cosmostypes.Error); ok {
return nil, errsdk
}
return nil, cosmostypes.ErrInternal(err.Error())
return nil, NewMesgWrapError(CodeInternal, err)
}
res, err := codec.MarshalBinaryBare(data)
if err != nil {
return nil, cosmostypes.ErrInternal(err.Error())
return nil, NewMesgWrapError(CodeInternal, err)
}
return res, nil
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/runner/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func (s *Backend) handler(request cosmostypes.Request, msg cosmostypes.Msg) (has
case msgCreateRunner:
run, err := s.Create(request, &msg)
if err != nil {
return nil, cosmostypes.ErrInternal(err.Error())
return nil, cosmos.NewMesgWrapError(cosmos.CodeInternal, err)
}
return run.Hash, nil
case msgDeleteRunner:
if err := s.Delete(request, &msg); err != nil {
return nil, err
return nil, cosmos.NewMesgWrapError(cosmos.CodeInternal, err)
}
return nil, nil
default:
Expand Down
7 changes: 4 additions & 3 deletions sdk/runner/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package runnersdk
import (
cosmostypes "github.com/cosmos/cosmos-sdk/types"
"github.com/mesg-foundation/engine/codec"
"github.com/mesg-foundation/engine/cosmos"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/x/xvalidator"
)
Expand Down Expand Up @@ -39,10 +40,10 @@ func (msg msgCreateRunner) ValidateBasic() cosmostypes.Error {
return cosmostypes.ErrInternal(err.Error())
}
if msg.ServiceHash.IsZero() {
return cosmostypes.ErrInternal("serviceHash is missing")
return cosmos.NewMesgErrorf(cosmos.CodeValidation, "serviceHash is missing")
}
if msg.EnvHash.IsZero() {
return cosmostypes.ErrInternal("envHash is missing")
return cosmos.NewMesgErrorf(cosmos.CodeValidation, "envHash is missing")
}
if msg.Address.Empty() {
return cosmostypes.ErrInvalidAddress("address is missing")
Expand Down Expand Up @@ -90,7 +91,7 @@ func (msg msgDeleteRunner) ValidateBasic() cosmostypes.Error {
return cosmostypes.ErrInternal(err.Error())
}
if msg.RunnerHash.IsZero() {
return cosmostypes.ErrInternal("runnerHash is missing")
return cosmos.NewMesgErrorf(cosmos.CodeValidation, "runnerHash is missing")
}
if msg.Address.Empty() {
return cosmostypes.ErrInvalidAddress("address is missing")
Expand Down
2 changes: 1 addition & 1 deletion sdk/service/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *Backend) handler(request cosmostypes.Request, msg cosmostypes.Msg) (has
case msgCreateService:
srv, err := s.Create(request, &msg)
if err != nil {
return nil, err
return nil, cosmos.NewMesgWrapError(cosmos.CodeInternal, err)
}
return srv.Hash, nil
default:
Expand Down