Commit 387b07c
authored
Allow error response customization (#828)
* Feat: custom error type support
Error responses of `lambda_runtime` are now customizable. One use case
is to avoid using `std::any::type_name` for error types, which is not
reliable for determining subsequent program behavior.
`F::Error` of `Runtime::run` and `run` is required to implement
`Into<Diagnostic<'a>>` instead of `Display`.
`EventErrorRequest` accepts a value implementing `Into<Diagnostic<'a>>`
instead of the error type and message.
`Diagnostic` becomes public because users may implement their own
conversions. Its fields are wrapped in `Cow` so that they can carry both
borrowed and owned strings. `Diagnostic` is implemented for every type
that implements `Display` as a fallback, which also ensures backward
compatibility.
* Chore: add example to comments on Diagnostic
The comments on `Diagnositc` shows how to customize error responses with
an example.1 parent fabffbc commit 387b07c
3 files changed
+87
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | | - | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| |||
96 | 99 | | |
97 | 100 | | |
98 | 101 | | |
99 | | - | |
| 102 | + | |
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
| |||
173 | 176 | | |
174 | 177 | | |
175 | 178 | | |
176 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
177 | 187 | | |
178 | 188 | | |
179 | 189 | | |
| |||
224 | 234 | | |
225 | 235 | | |
226 | 236 | | |
227 | | - | |
| 237 | + | |
228 | 238 | | |
229 | 239 | | |
230 | 240 | | |
| |||
249 | 259 | | |
250 | 260 | | |
251 | 261 | | |
252 | | - | |
| 262 | + | |
253 | 263 | | |
254 | | - | |
| 264 | + | |
255 | 265 | | |
256 | 266 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
| 267 | + | |
261 | 268 | | |
262 | 269 | | |
263 | 270 | | |
| |||
274 | 281 | | |
275 | 282 | | |
276 | 283 | | |
277 | | - | |
| 284 | + | |
278 | 285 | | |
279 | 286 | | |
280 | 287 | | |
| |||
341 | 348 | | |
342 | 349 | | |
343 | 350 | | |
344 | | - | |
345 | | - | |
| 351 | + | |
| 352 | + | |
346 | 353 | | |
347 | 354 | | |
348 | 355 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| 200 | + | |
204 | 201 | | |
205 | 202 | | |
206 | 203 | | |
| |||
226 | 223 | | |
227 | 224 | | |
228 | 225 | | |
229 | | - | |
230 | | - | |
| 226 | + | |
| 227 | + | |
231 | 228 | | |
232 | 229 | | |
233 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
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 | + | |
16 | 50 | | |
17 | 51 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 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 | + | |
21 | 77 | | |
22 | 78 | | |
23 | 79 | | |
| |||
315 | 371 | | |
316 | 372 | | |
317 | 373 | | |
318 | | - | |
319 | | - | |
| 374 | + | |
| 375 | + | |
320 | 376 | | |
321 | 377 | | |
322 | 378 | | |
| |||
0 commit comments