Skip to content

Conversation

leoromanovsky
Copy link
Member

@leoromanovsky leoromanovsky commented Sep 27, 2023

…-968)


labels: mergeable

Fixes: #issue

Motivation and Context

Exceptions within the Eppo SDK should not bubble up to the customers' applications.

Description

By default the graceful mode is enabled; all exceptions are captured in the top level public methods and logged.

For development the graceful mode can be disabled:

client.setIsGracefulFailureMode(false)

How has this been tested?

It was easy to test the logger because we can pass a mock - it wasn't obvious to me how to trigger an exception to be able to test the graceful mode. We'd need to stub getAssignmentVariation but this seems unnecessary.

Suggestions welcome.

deployment plan

Bump version number and import into upstream.

Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd include unit tests that mock out bad calls for both failures modes to verify exception is thrown / null returned.
Happy to pair on the mocking if you'd like!

export default class EppoClient implements IEppoClient {
private queuedEvents: IAssignmentEvent[] = [];
private assignmentLogger: IAssignmentLogger | undefined;
private isGracefulFailureMode = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Comment on lines +125 to +127
try {
return (
this.getAssignmentVariation(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all these functions do is immediately delegate to getAssignmentVariation(), I'm thinking it would be cleaner to just have the try-catch in that method and forgo it in these user-facing syntactic sugar wrappers.

);
} catch (error) {
if (this.isGracefulFailureMode) {
console.error(`[Eppo SDK] Error getting assignment: ${error.message}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider just logging the error so we get the stack trace as well.

console.error('[Eppo SDK] Error getting assignment', error.message);

Comment on lines +340 to +342
public setIsGracefulFailureMode(gracefulFailureMode: boolean) {
this.isGracefulFailureMode = gracefulFailureMode;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea thank you - good idea!

@aarsilv aarsilv assigned leoromanovsky and unassigned aarsilv Sep 27, 2023
Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pairing and iterating! 🎉

},
};

describe('error encountered', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

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