Skip to content

Commit

Permalink
feat: specification-0.5.0 (#44)
Browse files Browse the repository at this point in the history
* feature/spec-0.3.0: Update docs on merging contexts to reflect spec

Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>

* feature/spec-0.5.0: Ensure error message is optional and error code required when an error has been found
Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>

Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>

* feature/spec-0.5.0: Remove returns in exception docstrings
Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>

Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>

Signed-off-by: Andrew Helsby <ajhelsby@hotmail.com>
  • Loading branch information
ajhelsby authored Nov 11, 2022
1 parent 311b8ee commit 04a4323
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
File renamed without changes.
41 changes: 20 additions & 21 deletions open_feature/exception/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from open_feature.flag_evaluation.error_code import ErrorCode
import typing

from open_feature.exception.error_code import ErrorCode


class OpenFeatureError(Exception):
Expand All @@ -7,13 +9,14 @@ class OpenFeatureError(Exception):
the more specific exceptions extending this one should be used.
"""

def __init__(self, error_message: str = None, error_code: ErrorCode = None):
def __init__(
self, error_message: typing.Optional[str] = None, error_code: ErrorCode = None
):
"""
Constructor for the generic OpenFeatureError.
@param error_message: a string message representing why the error has been
raised
@param error_message: an optional string message representing why the
error has been raised
@param error_code: the ErrorCode string enum value for the type of error
@return: the generic OpenFeatureError exception
"""
self.error_message = error_message
self.error_code = error_code
Expand All @@ -25,13 +28,12 @@ class FlagNotFoundError(OpenFeatureError):
key provided by the user.
"""

def __init__(self, error_message: str = None):
def __init__(self, error_message: typing.Optional[str] = None):
"""
Constructor for the FlagNotFoundError. The error code for
this type of exception is ErrorCode.FLAG_NOT_FOUND.
@param error_message: a string message representing why the error has been
raised
@return: the generic FlagNotFoundError exception
@param error_message: an optional string message representing
why the error has been raised
"""
super().__init__(error_message, ErrorCode.FLAG_NOT_FOUND)

Expand All @@ -42,13 +44,12 @@ class GeneralError(OpenFeatureError):
feature python sdk.
"""

def __init__(self, error_message: str = None):
def __init__(self, error_message: typing.Optional[str] = None):
"""
Constructor for the GeneralError. The error code for this type of exception
is ErrorCode.GENERAL.
@param error_message: a string message representing why the error has been
raised
@return: the generic GeneralError exception
@param error_message: an optional string message representing why the error
has been raised
"""
super().__init__(error_message, ErrorCode.GENERAL)

Expand All @@ -59,13 +60,12 @@ class ParseError(OpenFeatureError):
be parsed into a FlagEvaluationDetails object.
"""

def __init__(self, error_message: str = None):
def __init__(self, error_message: typing.Optional[str] = None):
"""
Constructor for the ParseError. The error code for this type of exception
is ErrorCode.PARSE_ERROR.
@param error_message: a string message representing why the error has been
raised
@return: the generic ParseError exception
@param error_message: an optional string message representing why the
error has been raised
"""
super().__init__(error_message, ErrorCode.PARSE_ERROR)

Expand All @@ -76,13 +76,12 @@ class TypeMismatchError(OpenFeatureError):
not match the type requested by the user.
"""

def __init__(self, error_message: str = None):
def __init__(self, error_message: typing.Optional[str] = None):
"""
Constructor for the TypeMismatchError. The error code for this type of
exception is ErrorCode.TYPE_MISMATCH.
@param error_message: a string message representing why the error has been
raised
@return: the generic TypeMismatchError exception
@param error_message: an optional string message representing why the
error has been raised
"""
super().__init__(error_message, ErrorCode.TYPE_MISMATCH)

Expand Down
4 changes: 2 additions & 2 deletions open_feature/flag_evaluation/flag_evaluation_details.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing
from dataclasses import dataclass

from open_feature.flag_evaluation.error_code import ErrorCode
from open_feature.exception.error_code import ErrorCode
from open_feature.flag_evaluation.reason import Reason


Expand All @@ -12,4 +12,4 @@ class FlagEvaluationDetails:
variant: str = None
reason: Reason = None
error_code: ErrorCode = None
error_message: str = None
error_message: typing.Optional[str] = None
3 changes: 2 additions & 1 deletion open_feature/open_feature_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import typing

from open_feature.evaluation_context.evaluation_context import EvaluationContext
from open_feature.exception.error_code import ErrorCode
from open_feature.exception.exceptions import (
GeneralError,
OpenFeatureError,
TypeMismatchError,
)
from open_feature.flag_evaluation.error_code import ErrorCode
from open_feature.flag_evaluation.flag_evaluation_details import FlagEvaluationDetails
from open_feature.flag_evaluation.flag_evaluation_options import FlagEvaluationOptions
from open_feature.flag_evaluation.flag_type import FlagType
Expand Down Expand Up @@ -248,6 +248,7 @@ def evaluate_flag_details(
# https://github.com/open-feature/spec/blob/main/specification/sections/03-evaluation-context.md
# Any resulting evaluation context from a before hook will overwrite
# duplicate fields defined globally, on the client, or in the invocation.
# Requirement 3.2.2, 4.3.4: API.context->client.context->invocation.context
invocation_context = before_hooks(
flag_type, hook_context, merged_hooks, None
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_open_feature_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from open_feature.exception.error_code import ErrorCode
from open_feature.exception.exceptions import GeneralError
from open_feature.flag_evaluation.error_code import ErrorCode
from open_feature.open_feature_api import get_client, get_provider, set_provider
from open_feature.provider.no_op_provider import NoOpProvider

Expand Down
2 changes: 1 addition & 1 deletion tests/test_open_feature_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest

from open_feature.exception.error_code import ErrorCode
from open_feature.exception.exceptions import OpenFeatureError
from open_feature.flag_evaluation.error_code import ErrorCode
from open_feature.flag_evaluation.reason import Reason
from open_feature.hooks.hook import Hook

Expand Down
2 changes: 1 addition & 1 deletion tests/test_open_feature_evaluation_context.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

from open_feature.evaluation_context.evaluation_context import EvaluationContext
from open_feature.exception.error_code import ErrorCode
from open_feature.exception.exceptions import GeneralError
from open_feature.flag_evaluation.error_code import ErrorCode
from open_feature.open_feature_evaluation_context import (
api_evaluation_context,
set_api_evaluation_context,
Expand Down

0 comments on commit 04a4323

Please sign in to comment.