Skip to content
This repository was archived by the owner on Nov 16, 2020. It is now read-only.

Commit a5fd9fc

Browse files
authored
Add Error Handling spec (#424)
1 parent a37e57b commit a5fd9fc

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
layout: default
3+
---
4+
# Error handling for functions
5+
6+
## Types of Errors
7+
### “User” / Input Errors
8+
9+
These errors are detected **by functions** themselves (early in the function body) or **input schema validation**. When such error is detected, it makes no sense to proceed: if a function expects a string, but the input is a map, there’s nothing meaningful the function can do with it.
10+
11+
It is normal for a well implemented function to reject wrong input. Such errors mean that something is wrong with the **input data**.
12+
13+
14+
### Function Errors
15+
16+
These errors are thrown (usually **by the language runtime**) as a result of a logic error, such as NullPointerException or ArithmeticException (“divide by zero”).
17+
18+
Such error means that something is wrong with the **function**.
19+
20+
Examples:
21+
22+
- external services failures
23+
- output validation errors
24+
- timeout error
25+
- other runtime exceptions
26+
27+
28+
### System / Infrastructure Errors
29+
30+
These errors prevent function invocation from happening or communicating the results of the invocation back.
31+
32+
Such error means something is wrong with Dispatch itself or its underlying infrastructure.
33+
34+
35+
## How errors are thrown
36+
37+
User errors (thrown by function code) and function errors are language dependent. To reduce dependency on image-specific conventions, language standard errors should be used whenever possible.
38+
39+
It is the responsibility of language base-images to communicate those errors back in the output context.
40+
41+
42+
## Communicating errors
43+
44+
Input and function errors should be recorded in the invocation output context and communicated back to the original caller. If a user API (via the API Gateway) call translated to a function invocation resulting in an input or function error, that error should be communicated back through that API using an appropriate HTTP status.
45+
46+
System errors are logged to Dispatch system logs. If a system error is detected invoking a function, it should also be recorded in the output context.
47+
48+
49+
### Error structure
50+
51+
If an invocation resulted in an error, the output context will have a non-null `error` field.
52+
For example (in YAML):
53+
54+
context:
55+
error:
56+
type: FunctionError
57+
message: 'Something strange happened'
58+
stacktrace: ['...', '...']
59+
logs:
60+
stdout: ['...', '...']
61+
stderr: ['...', '...']
62+
payload: ~
63+
64+
Error fields:
65+
66+
- `**type**` — one of `InputError`, `FunctionError` or `SystemError`
67+
- `**message**` — a string: the error’s message (every error comes with a message)
68+
- `**stacktrace**` — a list of strings, can be empty: a stack trace or traceback of the error
69+

0 commit comments

Comments
 (0)