-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add typed versions of get_assignment() #7
Conversation
41c5fd0
to
e659108
Compare
@@ -23,9 +23,8 @@ pub fn main() -> eppo::Result<()> { | |||
|
|||
// Get assignment for test-subject. | |||
let assignment = client | |||
.get_assignment("a-boolean-flag", "test-subject", &HashMap::new()) | |||
.get_boolean_assignment("a-boolean-flag", "test-subject", &HashMap::new()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
/// # Errors | ||
/// | ||
/// Returns an error in the following cases: | ||
/// - [`Error::FlagNotFound`] if the requested flag configuration was not found. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could happen if someone adds the get_*_assignment
function to their code but hasn't yet configured a flag in eppo.cloud. This is a normal flow and from the perspective of the client, should not throw an error.
What I want to happen, from the client's perspective, is the default_value
be returned. However the FlagNotFound
can be returned in some way to inform users of the reason for the value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's almost exactly what happens in the example.
client.get_boolean_assignment("non-existent", ...) // Err(Error::FlagNotFound)
// log error (or skip next line and rely on logger)
.inspect_err(|err| eprintln!("error: {:?}", err)
.unwrap_or_default() // ignoring errors. Err(_) -> None
.unwrap_or(false); // default value. None -> false
The functions doesn't "throw" and error, it returns Err(Error::FlagNotFound)
to indicate that some attention might be needed, and the user can easily ignore it and continue processing with default value.
&self, | ||
flag_key: &str, | ||
subject_key: &str, | ||
subject_attributes: &SubjectAttributes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a default_value: String
parameter, or whatever the type is returned, to all public get_*_assignment
methods. This will match our APIs in other SDKs: https://github.com/Eppo-exp/js-client-sdk-common/blob/main/src/client/eppo-client.ts#L45-L78
e659108
to
8d3b713
Compare
No description provided.