Skip to content
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

Merged
merged 1 commit into from
May 17, 2024

Conversation

rasendubi
Copy link
Collaborator

No description provided.

@rasendubi rasendubi force-pushed the feat-typed-get-assignment branch from 41c5fd0 to e659108 Compare May 15, 2024 19:56
@rasendubi
Copy link
Collaborator Author

I included f754132 to minimize merge conflict with #6.

@@ -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())
Copy link
Member

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.
Copy link
Member

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.

Copy link
Collaborator Author

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,
Copy link
Member

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

@rasendubi rasendubi force-pushed the feat-typed-get-assignment branch from e659108 to 8d3b713 Compare May 16, 2024 11:35
@rasendubi rasendubi merged commit 75e4ccf into main May 17, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants