-
Notifications
You must be signed in to change notification settings - Fork 6
SCAL-256912 Enhance error handling by introducing EmbedErrorEvent interface #329
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
base: main
Are you sure you want to change the base?
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Summary of ChangesHello @shivam-kumar-ts, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the error handling mechanism within the SDK by introducing a standardized Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request is a great step towards more robust error handling by introducing the EmbedErrorEvent interface. The transition from string-based errors to structured error objects is well-executed across the affected components. My feedback focuses on enhancing this new structure by improving consistency in error handling logic, increasing the specificity of error codes for better diagnostics, and ensuring the semantic correctness of error types.
src/embed/ts-embed.ts
Outdated
| this.executeCallbacks(EmbedEvent.Error, { | ||
| offlineWarning, | ||
| }); | ||
| logger.warn(offlineWarning); | ||
| errorType: 'API', | ||
| message: ERROR_MESSAGE.OFFLINE_WARNING, | ||
| code: 'NETWORK_ERROR', | ||
| source: 'SDK', | ||
| details: { | ||
| event: e, | ||
| }, | ||
| error: ERROR_MESSAGE.OFFLINE_WARNING, | ||
| } as EmbedErrorEvent); | ||
| logger.warn(ERROR_MESSAGE.OFFLINE_WARNING); |
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.
For consistency with other error handling in this class, it would be better to use this.handleError() here instead of calling this.executeCallbacks() directly. The current implementation doesn't set this.isError = true, which might lead to inconsistent state. Using handleError will also centralize error logging.
Additionally, since this is a network-related event, consider changing the source from 'SDK' to 'NETWORK' to be more descriptive.
Note that handleError uses logger.error, while the original code used logger.warn. This change seems appropriate for an offline event, but please confirm if this is the desired behavior.
| this.executeCallbacks(EmbedEvent.Error, { | |
| offlineWarning, | |
| }); | |
| logger.warn(offlineWarning); | |
| errorType: 'API', | |
| message: ERROR_MESSAGE.OFFLINE_WARNING, | |
| code: 'NETWORK_ERROR', | |
| source: 'SDK', | |
| details: { | |
| event: e, | |
| }, | |
| error: ERROR_MESSAGE.OFFLINE_WARNING, | |
| } as EmbedErrorEvent); | |
| logger.warn(ERROR_MESSAGE.OFFLINE_WARNING); | |
| this.handleError({ | |
| errorType: 'API', | |
| message: ERROR_MESSAGE.OFFLINE_WARNING, | |
| code: 'NETWORK_ERROR', | |
| source: 'NETWORK', | |
| details: { | |
| event: e, | |
| }, | |
| error: ERROR_MESSAGE.OFFLINE_WARNING, | |
| } as EmbedErrorEvent); |
src/embed/ts-embed.ts
Outdated
| this.handleError({ | ||
| errorType: 'VALIDATION_ERROR', | ||
| message: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG, | ||
| code: 'VALIDATION_ERROR', | ||
| source: 'SDK', | ||
| details: {}, | ||
| error: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG, | ||
| } as EmbedErrorEvent); |
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.
The code property in the error object is set to 'VALIDATION_ERROR', which is the same as errorType. To make error diagnostics more precise, it's better to use a more specific error code. Consider using 'CONFLICTING_ACTIONS_CONFIG' for the code. This will also require updating the corresponding test expectations.
| this.handleError({ | |
| errorType: 'VALIDATION_ERROR', | |
| message: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG, | |
| code: 'VALIDATION_ERROR', | |
| source: 'SDK', | |
| details: {}, | |
| error: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG, | |
| } as EmbedErrorEvent); | |
| this.handleError({ | |
| errorType: 'VALIDATION_ERROR', | |
| message: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG, | |
| code: 'CONFLICTING_ACTIONS_CONFIG', | |
| source: 'SDK', | |
| details: {}, | |
| error: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG, | |
| } as EmbedErrorEvent); |
src/embed/ts-embed.ts
Outdated
| this.handleError({ | ||
| errorType: 'VALIDATION_ERROR', | ||
| message: ERROR_MESSAGE.CONFLICTING_TABS_CONFIG, | ||
| code: 'VALIDATION_ERROR', | ||
| source: 'SDK', | ||
| details: {}, | ||
| error: ERROR_MESSAGE.CONFLICTING_TABS_CONFIG, | ||
| } as EmbedErrorEvent); |
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.
Similar to the conflicting actions error, the code here is 'VALIDATION_ERROR', which is redundant with errorType. Using a more specific code like 'CONFLICTING_TABS_CONFIG' would improve error identification. Remember to update the related tests.
| this.handleError({ | |
| errorType: 'VALIDATION_ERROR', | |
| message: ERROR_MESSAGE.CONFLICTING_TABS_CONFIG, | |
| code: 'VALIDATION_ERROR', | |
| source: 'SDK', | |
| details: {}, | |
| error: ERROR_MESSAGE.CONFLICTING_TABS_CONFIG, | |
| } as EmbedErrorEvent); | |
| this.handleError({ | |
| errorType: 'VALIDATION_ERROR', | |
| message: ERROR_MESSAGE.CONFLICTING_TABS_CONFIG, | |
| code: 'CONFLICTING_TABS_CONFIG', | |
| source: 'SDK', | |
| details: {}, | |
| error: ERROR_MESSAGE.CONFLICTING_TABS_CONFIG, | |
| } as EmbedErrorEvent); |
src/embed/ts-embed.ts
Outdated
| this.handleError({ | ||
| errorType: 'INVALID_OPERATOR', | ||
| message: ERROR_MESSAGE.RENDER_BEFORE_EVENTS_REQUIRED, | ||
| code: 'RENDER_NOT_CALLED', | ||
| source: 'SDK', | ||
| details: {}, | ||
| error: ERROR_MESSAGE.RENDER_BEFORE_EVENTS_REQUIRED, | ||
| } as EmbedErrorEvent); |
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.
The errorType is set to 'INVALID_OPERATOR'. According to the documentation for EmbedEvent.Error, this type is intended for errors related to filter operators. Since this error is about calling trigger before render, a more semantically correct errorType would be 'VALIDATION_ERROR'. This would better reflect that it's a state validation failure.
| this.handleError({ | |
| errorType: 'INVALID_OPERATOR', | |
| message: ERROR_MESSAGE.RENDER_BEFORE_EVENTS_REQUIRED, | |
| code: 'RENDER_NOT_CALLED', | |
| source: 'SDK', | |
| details: {}, | |
| error: ERROR_MESSAGE.RENDER_BEFORE_EVENTS_REQUIRED, | |
| } as EmbedErrorEvent); | |
| this.handleError({ | |
| errorType: 'VALIDATION_ERROR', | |
| message: ERROR_MESSAGE.RENDER_BEFORE_EVENTS_REQUIRED, | |
| code: 'RENDER_NOT_CALLED', | |
| source: 'SDK', | |
| details: {}, | |
| error: ERROR_MESSAGE.RENDER_BEFORE_EVENTS_REQUIRED, | |
| } as EmbedErrorEvent); |
src/embed/conversation.ts
Outdated
| this.handleError({ | ||
| errorType: 'VALIDATION_ERROR', | ||
| message: ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, | ||
| code: 'VALIDATION_ERROR', | ||
| source: 'SDK', | ||
| details: {}, | ||
| error: ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, | ||
| } as EmbedErrorEvent); |
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.
The code property is set to 'VALIDATION_ERROR', which is the same as errorType. For better error diagnostics, consider using a more specific code, such as 'WORKSHEET_ID_NOT_FOUND'. This will require an update to the test expectations in src/embed/conversation.spec.ts.
| this.handleError({ | |
| errorType: 'VALIDATION_ERROR', | |
| message: ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, | |
| code: 'VALIDATION_ERROR', | |
| source: 'SDK', | |
| details: {}, | |
| error: ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, | |
| } as EmbedErrorEvent); | |
| this.handleError({ | |
| errorType: 'VALIDATION_ERROR', | |
| message: ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, | |
| code: 'WORKSHEET_ID_NOT_FOUND', | |
| source: 'SDK', | |
| details: {}, | |
| error: ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, | |
| } as EmbedErrorEvent); |
src/embed/liveboard.ts
Outdated
| this.handleError({ | ||
| errorType: 'VALIDATION_ERROR', | ||
| message: ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION, | ||
| code: 'VALIDATION_ERROR', | ||
| source: 'SDK', | ||
| details: {}, | ||
| error: ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION, | ||
| } as EmbedErrorEvent); |
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.
The code property is set to 'VALIDATION_ERROR', which is redundant as it's the same as errorType. A more specific code like 'LIVEBOARD_ID_MISSING' would be more helpful for debugging. Please update any relevant tests if they exist.
| this.handleError({ | |
| errorType: 'VALIDATION_ERROR', | |
| message: ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION, | |
| code: 'VALIDATION_ERROR', | |
| source: 'SDK', | |
| details: {}, | |
| error: ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION, | |
| } as EmbedErrorEvent); | |
| this.handleError({ | |
| errorType: 'VALIDATION_ERROR', | |
| message: ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION, | |
| code: 'LIVEBOARD_ID_MISSING', | |
| source: 'SDK', | |
| details: {}, | |
| error: ERROR_MESSAGE.LIVEBOARD_VIZ_ID_VALIDATION, | |
| } as EmbedErrorEvent); |
commit: |
4727f6d to
d764c61
Compare
678e4e4 to
b68c845
Compare
|
SonarQube Quality Gate
|








Uh oh!
There was an error while loading. Please reload this page.