Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 1 | package lib |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | |
| 6 | "veyron2/ipc" |
| 7 | "veyron2/verror" |
| 8 | |
| 9 | sample "veyron/examples/wspr_sample" |
| 10 | ) |
| 11 | |
| 12 | // NewCached returns a new implementation of the ErrorThrowerService. |
| 13 | func NewErrorThrower() sample.ErrorThrowerService { |
| 14 | return &errorThrowerImpl{} |
| 15 | } |
| 16 | |
| 17 | type errorThrowerImpl struct{} |
| 18 | |
| 19 | func (e *errorThrowerImpl) ThrowAborted(_ ipc.Context) error { |
| 20 | return verror.Abortedf("Aborted!") |
| 21 | } |
| 22 | |
| 23 | func (e *errorThrowerImpl) ThrowBadArg(_ ipc.Context) error { |
| 24 | return verror.BadArgf("BadArg!") |
| 25 | } |
| 26 | |
| 27 | func (e *errorThrowerImpl) ThrowBadProtocol(_ ipc.Context) error { |
| 28 | return verror.BadProtocolf("BadProtocol!") |
| 29 | } |
| 30 | |
| 31 | func (e *errorThrowerImpl) ThrowInternal(_ ipc.Context) error { |
| 32 | return verror.Internalf("Internal!") |
| 33 | } |
| 34 | |
| 35 | func (e *errorThrowerImpl) ThrowNotAuthorized(_ ipc.Context) error { |
| 36 | return verror.NotAuthorizedf("NotAuthorized!") |
| 37 | } |
| 38 | |
| 39 | func (e *errorThrowerImpl) ThrowNotFound(_ ipc.Context) error { |
| 40 | return verror.NotFoundf("NotFound!") |
| 41 | } |
| 42 | |
| 43 | func (e *errorThrowerImpl) ThrowUnknown(_ ipc.Context) error { |
| 44 | return verror.Unknownf("Unknown!") |
| 45 | } |
| 46 | |
| 47 | func (e *errorThrowerImpl) ThrowGoError(_ ipc.Context) error { |
| 48 | return errors.New("GoError!") |
| 49 | } |
| 50 | |
| 51 | func (e *errorThrowerImpl) ThrowCustomStandardError(_ ipc.Context) error { |
| 52 | return verror.Standard{ |
| 53 | ID: "MyCustomError", |
| 54 | Msg: "CustomStandard!", |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func (e *errorThrowerImpl) ListAllBuiltInErrorIDs(_ ipc.Context) ([]string, error) { |
| 59 | // TODO(aghassemi) Use when we have enum for error IDs in IDL |
| 60 | // This is not used yet but the idea is to pass all error types in veyron2/verror to |
| 61 | // JavaScript so if a new one is added, this test would break and we add the new one to |
| 62 | // JavaScript as well. There is no way to enumerate all error IDs right now since they |
| 63 | // are constants and not an Enum. Enum support is coming later. |
| 64 | return nil, nil |
| 65 | } |