blob: 3ad7e6804241e381ce33c65403cf99cda719baa9 [file] [log] [blame]
Jiri Simsa5293dcb2014-05-10 09:56:38 -07001package lib
2
3import (
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.
13func NewErrorThrower() sample.ErrorThrowerService {
14 return &errorThrowerImpl{}
15}
16
17type errorThrowerImpl struct{}
18
19func (e *errorThrowerImpl) ThrowAborted(_ ipc.Context) error {
20 return verror.Abortedf("Aborted!")
21}
22
23func (e *errorThrowerImpl) ThrowBadArg(_ ipc.Context) error {
24 return verror.BadArgf("BadArg!")
25}
26
27func (e *errorThrowerImpl) ThrowBadProtocol(_ ipc.Context) error {
28 return verror.BadProtocolf("BadProtocol!")
29}
30
31func (e *errorThrowerImpl) ThrowInternal(_ ipc.Context) error {
32 return verror.Internalf("Internal!")
33}
34
35func (e *errorThrowerImpl) ThrowNotAuthorized(_ ipc.Context) error {
36 return verror.NotAuthorizedf("NotAuthorized!")
37}
38
39func (e *errorThrowerImpl) ThrowNotFound(_ ipc.Context) error {
40 return verror.NotFoundf("NotFound!")
41}
42
43func (e *errorThrowerImpl) ThrowUnknown(_ ipc.Context) error {
44 return verror.Unknownf("Unknown!")
45}
46
47func (e *errorThrowerImpl) ThrowGoError(_ ipc.Context) error {
48 return errors.New("GoError!")
49}
50
51func (e *errorThrowerImpl) ThrowCustomStandardError(_ ipc.Context) error {
52 return verror.Standard{
53 ID: "MyCustomError",
54 Msg: "CustomStandard!",
55 }
56}
57
58func (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}