-
Notifications
You must be signed in to change notification settings - Fork 323
/
errors.go
137 lines (105 loc) · 3.74 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package api
import (
"encr.dev/pkg/errors"
)
const rawHint = `hint: signature must be func(http.ResponseWriter, *http.Request)
For more information on how to use raw APIs see https://encore.dev/docs/primitives/services-and-apis#raw-endpoints`
const baseHint = "For more information on how to use APIs see https://encore.dev/docs/primitives/services-and-apis"
var (
errRange = errors.Range(
"api",
`hint: valid signatures are:
- func(context.Context) error
- func(context.Context) (*ResponseData, error)
- func(context.Context, *RequestData) error
- func(context.Context, *RequestType) (*ResponseData, error)
For more information on how to use APIs, see https://encore.dev/docs/primitives/services-and-apis#defining-apis`,
errors.WithRangeSize(50),
)
errDuplicateAccessOptions = errRange.Newf(
"Invalid API Directive",
"Multiple access options have been defined for the API; %s and %s. Pick once from %s.",
)
errInvalidEndpointMethod = errRange.Newf(
"Invalid API Directive",
"Invalid endpoint method %q.",
)
errEndpointMethodMustBeAllCaps = errRange.New(
"Invalid API Directive",
"Endpoint method must be ALLCAPS.",
)
errRawEndpointCantBePrivate = errRange.New(
"Invalid API Directive",
"Private APIs cannot be declared as raw endpoints.",
)
errWrongNumberParams = errRange.Newf(
"Invalid API Function",
"API functions must have at least 1 parameter, found %d parameters.",
)
errWrongNumberResults = errRange.Newf(
"Invalid API Function",
"API functions must have at most 1 or 2 results, found %d results.",
)
errInvalidFirstParam = errRange.New(
"Invalid API Function",
"The first parameter of an API function must be context.Context.",
)
errMultiplePayloads = errRange.New(
"Invalid API Function",
"API functions can only have one payload parameter.",
)
errInvalidPathParams = errRange.Newf(
"Invalid API Function",
"Expected function parameters named '%s' to match Endpoint path params.",
)
errLastResultMustBeError = errRange.New(
"Invalid API Function",
"The last result of an API function must be error.",
)
errInvalidRawParams = errRange.Newf(
"Invalid API Function",
"Raw APIs must have a two parameters of type http.ResponseWriter and *http.Request, got %d parameters.",
errors.WithDetails(rawHint),
)
errInvalidRawResults = errRange.Newf(
"Invalid API Function",
"Raw APIs must not return any results, got %d results.",
errors.WithDetails(rawHint),
)
errRawNotResponeWriter = errRange.New(
"Invalid API Function",
"Raw APIs must have a first parameter of type http.ResponseWriter.",
errors.WithDetails(rawHint),
)
errRawNotRequest = errRange.New(
"Invalid API Function",
"Raw APIs must have a second parameter of type *http.Request.",
errors.WithDetails(rawHint),
)
errUnexpectedParameterName = errRange.Newf(
"Invalid API Function",
"Unexpected parameter name %q expected %q (to match path parameter %q).",
)
errWildcardMustBeString = errRange.Newf(
"Invalid API Function",
"Wildcard parameter %q must be a string.",
)
errInvalidPathParamType = errRange.Newf(
"Invalid API Function",
"Path parameter %q must be a string, bool, integer, or encore.dev/types/uuid.UUID.",
)
ErrInvalidEndpointUsage = errRange.New(
"Invalid API Usage",
"APIs can not be referenced without being called, unless they are used as a cron job endpoint, or a PubSub subscription handler.",
errors.WithDetails(baseHint),
)
ErrAPICalledOutsideService = errRange.New(
"Invalid API call",
"APIs can only be called from within a service, the current call site is outside any services within the application.",
errors.WithDetails(baseHint),
)
ErrRawEndpointsCannotBeCalled = errRange.New(
"Invalid API call",
"Raw APIs cannot be called from within an Encore application.",
)
)