-
Notifications
You must be signed in to change notification settings - Fork 7
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: |
b68c845 to
3301d3e
Compare
fa1049d to
7b478a3
Compare
| }); | ||
| // Log error | ||
| logger.error(error); | ||
| logger.error(errorDetails); |
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.
We can remove this.
a619520 to
31adaa6
Compare
src/embed/ts-embed.ts
Outdated
| offlineWarning, | ||
| }); | ||
| logger.warn(offlineWarning); | ||
| const errorDetails = { errorType: 'API', message: ERROR_MESSAGE.OFFLINE_WARNING, code: ERROR_CODE.NETWORK_ERROR, source: 'NETWORK', details: { event: e, } } as EmbedErrorDetailsEvent; |
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.
how is this api type? maybe we can have network in the error type
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.
I think offline, so api failed so added it
so should i remove it?
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.
Done!
src/types.ts
Outdated
| * @version SDK: 1.44.0 | ThoughtSpot: 26.2.0.cl | ||
| */ | ||
| export interface EmbedErrorDetailsEvent { | ||
| errorType: 'API' | 'FULLSCREEN' | 'SINGLE_VALUE_FILTER' | 'NON_EXIST_FILTER' | 'INVALID_DATE_VALUE' | 'INVALID_OPERATOR' | 'VALIDATION_ERROR' | string; |
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.
use enum
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.
dont allow string
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.
in Embed.Error this six types are there so i added here along with string
src/types.ts
Outdated
| errorType: 'API' | 'FULLSCREEN' | 'SINGLE_VALUE_FILTER' | 'NON_EXIST_FILTER' | 'INVALID_DATE_VALUE' | 'INVALID_OPERATOR' | 'VALIDATION_ERROR' | string; | ||
| message: string | string[]; | ||
| code: string; | ||
| source?: 'API' | 'NETWORK' | 'SDK'; |
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.
enum
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.
in Embed.Error this six types are there so i added here along with string
src/types.ts
Outdated
| * @version SDK: 1.44.0 | ThoughtSpot: 26.2.0.cl | ||
| */ | ||
| export interface EmbedErrorDetailsEvent { | ||
| errorType: 'API' | 'FULLSCREEN' | 'SINGLE_VALUE_FILTER' | 'NON_EXIST_FILTER' | 'INVALID_DATE_VALUE' | 'INVALID_OPERATOR' | 'VALIDATION_ERROR' | string; |
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.
dont allow string
src/types.ts
Outdated
| * @param message - A human-readable error message describing what went wrong. | ||
| * @param code - Error code providing a machine-readable identifier for the error. | ||
| * @param source - The source system or component where the error originated. | ||
| * @param details - Additional error details providing context-specific information. |
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.
why is error code needed ? what is diff btw that an error type
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.
Error code is unique and error type is a type which error belong to
src/embed/ts-embed.spec.ts
Outdated
| errorType: 'VALIDATION_ERROR', | ||
| message: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG, | ||
| code: ERROR_CODE.CONFLICTING_ACTIONS_CONFIG, | ||
| source: 'SDK', |
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.
where else will embed event error come from ? isnt this pointless ?
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.
src/types.ts
Outdated
| errorType: 'API' | 'FULLSCREEN' | 'SINGLE_VALUE_FILTER' | 'NON_EXIST_FILTER' | 'INVALID_DATE_VALUE' | 'INVALID_OPERATOR' | 'VALIDATION_ERROR' | string; | ||
| message: string | string[]; | ||
| code: string; | ||
| source?: 'API' | 'NETWORK' | 'SDK'; |
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.
why is this needed ? wont error type resolve this ?
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.
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.
ok but as a customer what will i do with this info ?
6bae6b5 to
4b19aec
Compare
b6de516 to
482b3a0
Compare
| if (!worksheetId) { | ||
| this.handleError(ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND); | ||
| this.handleError(ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND, { | ||
| errorType: ErrorDetailsTypes.VALIDATION_ERROR, |
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.
why is errorType and code both needed ? what is the use for source here ?
from customer's point of view arent all errors from sdk
src/embed/ts-embed.ts
Outdated
| code: ERROR_CODE.INIT_ERROR, | ||
| source: ErrorDetailsSources.SDK, | ||
| details: {}, | ||
| } as EmbedErrorDetailsEvent); |
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.
why is as needed here ?
src/types.ts
Outdated
| * }) | ||
| * ``` | ||
| */ | ||
| ErrorDetails = 'ErrorDetails', |
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.
why do we need a new embed event, the ticket says to improve the exiting event payload, whats the benefit of new event on its own ?
src/types.ts
Outdated
| export enum ErrorDetailsSources { | ||
| API = 'API', |
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.
what are the use cases for this ? this might confuse customers imo
| * - **Liveboard ID missing**: Errors related to missing liveboard ID | ||
| * - **Conflicting actions configuration**: Errors related to conflicting actions configuration | ||
| * - **Conflicting tabs configuration**: Errors related to conflicting tabs configuration | ||
| * - **Initialization error**: Errors related to initialization error |
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.
error description is added below as well. No need to add it twice.
…and remove unused ones
…h standardized error
68a6d66 to
5488d1b
Compare
|
SonarQube Quality Gate
|










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