diff --git a/specification.json b/specification.json index f79c8769..bb457430 100644 --- a/specification.json +++ b/specification.json @@ -1004,6 +1004,13 @@ "RFC 2119 keyword": "MUST", "children": [] }, + { + "id": "Requirement 4.4.8", + "machine_id": "requirement_4_4_8", + "content": "If an error occurs in the `after` hooks, it is considered abnormal execution, and the default value MUST be returned.", + "RFC 2119 keyword": "MUST", + "children": [] + }, { "id": "Requirement 4.5.1", "machine_id": "requirement_4_5_1", diff --git a/specification/assets/gherkin/hooks.feature b/specification/assets/gherkin/hooks.feature index fc055416..8281d50c 100644 --- a/specification/assets/gherkin/hooks.feature +++ b/specification/assets/gherkin/hooks.feature @@ -47,3 +47,19 @@ Feature: Evaluation details through hooks | string | variant | null | | string | reason | ERROR | | string | error_code | TYPE_MISMATCH | + + @spec-4.4.8 + Scenario: Error in after hook + Given a client with added hook + And the "after" hook returns an error + And a boolean-flag with key "boolean-flag" and a fallback value "false" + When the flag was evaluated with details + Then the "before" hook should have been executed + And the "error" hook should have been executed + And the "finally" hooks should be called with evaluation details + | data_type | key | value | + | string | flag_key | boolean-flag | + | boolean | value | false | + | string | variant | null | + | string | reason | ERROR | + | string | error_code | GENERAL | diff --git a/specification/sections/04-hooks.md b/specification/sections/04-hooks.md index 6c8d6a13..ebc48120 100644 --- a/specification/sections/04-hooks.md +++ b/specification/sections/04-hooks.md @@ -345,6 +345,14 @@ In languages with try/catch semantics, this means that exceptions thrown in `err Before hooks can impact evaluation by various means, such as mutating the `evaluation context`. Therefore, an error in the `before` hooks is considered abnormal execution, and the default should be returned. +#### Requirement 4.4.8 + +> If an error occurs in the `after` hooks, it is considered abnormal execution, and the default value **MUST** be returned. + +After hooks can reject a resolution they consider invalid, which is what the validating hook pattern relies on. An error in the `after` hooks is therefore also abnormal execution, and the default should be returned. + +Errors in `error` and `finally` hooks are different: they are contained by [Requirement 4.4.4](#requirement-444) and [Requirement 4.4.3](#requirement-443) respectively, and do not change the value returned to the application author. + ### [Flag evaluation options](../types.md#evaluation-options) Usage might look something like: