Skip to content

Commit f74a8d9

Browse files
feat!: make error code an enum and include optional error message (#142)
See #141 for context. Signed-off-by: Ryan Lamb <[email protected]> Co-authored-by: Todd Baert <[email protected]>
1 parent e6434df commit f74a8d9

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

specification.json

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
{
139139
"id": "Requirement 1.4.7",
140140
"machine_id": "requirement_1_4_7",
141-
"content": "In cases of abnormal execution, the `evaluation details` structure's `error code` field MUST contain a string identifying an error occurred during flag evaluation and the nature of the error.",
141+
"content": "In cases of abnormal execution, the `evaluation details` structure's `error code` field MUST contain an `error code`.",
142142
"RFC 2119 keyword": "MUST",
143143
"children": []
144144
},
@@ -170,6 +170,13 @@
170170
"RFC 2119 keyword": "SHOULD",
171171
"children": []
172172
},
173+
{
174+
"id": "Requirement 1.4.12",
175+
"machine_id": "requirement_1_4_12",
176+
"content": "In cases of abnormal execution, the `evaluation details` structure's `error message` field MAY contain a string containing additional details about the nature of the error.",
177+
"RFC 2119 keyword": "MAY",
178+
"children": []
179+
},
173180
{
174181
"id": "Requirement 1.5.1",
175182
"machine_id": "requirement_1_5_1",
@@ -237,7 +244,7 @@
237244
{
238245
"id": "Requirement 2.8",
239246
"machine_id": "requirement_2_8",
240-
"content": "In cases of abnormal execution, the `provider` MUST indicate an error using the idioms of the implementation language, with an associated error code having possible values `\"PROVIDER_NOT_READY\"`, `\"FLAG_NOT_FOUND\"`, `\"PARSE_ERROR\"`, `\"TYPE_MISMATCH\"`, or `\"GENERAL\"`.",
247+
"content": "In cases of abnormal execution, the `provider` MUST indicate an error using the idioms of the implementation language, with an associated `error code` and optional associated `error message`.",
241248
"RFC 2119 keyword": "MUST",
242249
"children": []
243250
},
@@ -263,6 +270,20 @@
263270
"RFC 2119 keyword": "MUST",
264271
"children": []
265272
},
273+
{
274+
"id": "Requirement 2.11",
275+
"machine_id": "requirement_2_11",
276+
"content": "In cases of normal execution, the `provider` MUST NOT populate the `flag resolution` structure's `error message` field, or otherwise must populate it with a null or falsy value.",
277+
"RFC 2119 keyword": "MUST NOT",
278+
"children": []
279+
},
280+
{
281+
"id": "Requirement 2.12",
282+
"machine_id": "requirement_2_12",
283+
"content": "In cases of abnormal execution, the `evaluation details` structure's `error message` field MAY contain a string containing additional detail about the nature of the error.",
284+
"RFC 2119 keyword": "MAY",
285+
"children": []
286+
},
266287
{
267288
"id": "Requirement 3.1.1",
268289
"machine_id": "requirement_3_1_1",

specification/sections/01-flag-evaluation.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ FlagEvaluationDetails<MyStruct> myStructDetails = client.getObjectDetails<MyStru
185185
186186
##### Requirement 1.4.7
187187

188-
> In cases of abnormal execution, the `evaluation details` structure's `error code` field **MUST** contain a string identifying an error occurred during flag evaluation and the nature of the error.
188+
> In cases of abnormal execution, the `evaluation details` structure's `error code` field **MUST** contain an `error code`.
189189
190-
Some example error codes include: `"TARGETING_KEY_MISSING"`, `"PROVIDER_NOT_READY"`, `"FLAG_NOT_FOUND"`, `"PARSE_ERROR"`, `"TYPE_MISMATCH"`, or `"GENERAL"`.
190+
See [error code](../types.md#error-code) for details.
191191

192192
##### Requirement 1.4.8
193193

@@ -211,6 +211,10 @@ Implementations may define a standard logging interface that can be supplied as
211211
212212
It's recommended to provide non-blocking mechanisms for flag evaluation, particularly in languages or environments wherein there's a single thread of execution.
213213

214+
##### Requirement 1.4.12
215+
216+
> In cases of abnormal execution, the `evaluation details` structure's `error message` field **MAY** contain a string containing additional details about the nature of the error.
217+
214218
#### Evaluation Options
215219

216220
##### Requirement 1.5.1

specification/sections/02-providers.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,17 @@ As indicated in the definition of the [`flag resolution`](../types.md#resolution
8585
8686
##### Requirement 2.8
8787

88-
> In cases of abnormal execution, the `provider` **MUST** indicate an error using the idioms of the implementation language, with an associated error code having possible values `"PROVIDER_NOT_READY"`, `"FLAG_NOT_FOUND"`, `"PARSE_ERROR"`, `"TYPE_MISMATCH"`, or `"GENERAL"`.
88+
> In cases of abnormal execution, the `provider` **MUST** indicate an error using the idioms of the implementation language, with an associated `error code` and optional associated `error message`.
8989
9090
The provider might throw an exception, return an error, or populate the `error code` object on the returned `flag resolution` structure to indicate a problem during flag value resolution.
9191

92+
See [error code](../types.md#error-code) for details.
93+
94+
```typescript
95+
// example throwing an exception with an error code and optional error message.
96+
throw new ProviderError(ErrorCode.INVALID_CONTEXT, "The 'foo' attribute must be a string.");
97+
```
98+
9299
##### Condition 2.9
93100

94101
> The implementation language supports generics (or an equivalent feature).
@@ -133,3 +140,11 @@ class MyProvider implements Provider {
133140
//...
134141
}
135142
```
143+
144+
#### Requirement 2.11
145+
146+
> In cases of normal execution, the `provider` **MUST NOT** populate the `flag resolution` structure's `error message` field, or otherwise must populate it with a null or falsy value.
147+
148+
#### Requirement 2.12
149+
150+
> In cases of abnormal execution, the `evaluation details` structure's `error message` field **MAY** contain a string containing additional detail about the nature of the error.

specification/types.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ A structure representing the result of the [flag evaluation process](./glossary.
3636

3737
- flag key (string, required)
3838
- value (boolean | string | number | structure, required)
39-
- error code (string, optional)
39+
- error code ([error code](#error-code), optional)
40+
- error message (string, optional)
4041
- reason (string, optional)
4142
- variant (string, optional)
4243

@@ -45,7 +46,8 @@ A structure representing the result of the [flag evaluation process](./glossary.
4546
A structure which contains a subset of the fields defined in the `evaluation details`, representing the result of the provider's [flag resolution process](./glossary.md#resolving-flag-values), including:
4647

4748
- value (boolean | string | number | structure, required)
48-
- error code (string, optional)
49+
- error code ([error code](#error-code), optional)
50+
- error message (string, optional)
4951
- reason (string, optional)
5052
- variant (string, optional)
5153

@@ -62,6 +64,20 @@ A set of pre-defined reasons is enumerated below:
6264

6365
> NOTE: The `resolution details` structure is not exposed to the Application Author. It defines the data which Provider Authors must return when resolving the value of flags.
6466
67+
### Error Code
68+
69+
An enumerated error code represented idiomatically in the implementation language.
70+
71+
| Error Code | Explanation |
72+
|-----------------------|---------------------------------------------------------------------------------------------|
73+
| PROVIDER_NOT_READY | The value was resolved before the provider was ready. |
74+
| FLAG_NOT_FOUND | The flag could not be found. |
75+
| PARSE_ERROR | An error was encountered parsing data, such as a flag configuration. |
76+
| TYPE_MISMATCH | The type of the flag value does not match the expected type. |
77+
| TARGETING_KEY_MISSING | The provider requires a targeting key and one was not provided in the `evaluation context`. |
78+
| INVALID_CONTEXT | The `evaluation context` does not meet provider requirements. |
79+
| GENERAL | The error was for a reason not enumerated above. |
80+
6581
### Evaluation Options
6682

6783
A structure containing the following fields:

0 commit comments

Comments
 (0)