Skip to content

Conversation

@shivam-kumar-ts
Copy link
Contributor

@shivam-kumar-ts shivam-kumar-ts commented Oct 12, 2025

  • Enhance error handling in TsEmbed and related components by introducing EmbedErrorEvent interface.
  • Update error handling to use structured error objects for validation and API errors across various embed classes.

@shivam-kumar-ts shivam-kumar-ts requested a review from a team as a code owner October 12, 2025 23:44
@mnk-blr
Copy link
Collaborator

mnk-blr commented Oct 12, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 EmbedErrorEvent interface. This change ensures that all errors emitted by the SDK are structured consistently, providing richer context such as errorType, code, source, and details. This standardization improves the clarity and debuggability of error events for consumers of the SDK, making it easier to understand and respond to issues.

Highlights

  • Standardized Error Interface: Introduced a new EmbedErrorEvent interface to standardize the structure of error objects emitted by the SDK, providing consistent properties like errorType, message, code, source, and details.
  • Refactored Error Handling: The handleError method in TsEmbed and related components has been refactored to accept and process these new structured EmbedErrorEvent objects, replacing previous calls that used simple strings or generic objects.
  • Consistent Error Reporting: Updated error handling logic across ConversationEmbed, LiveboardEmbed, and TsEmbed to construct and pass EmbedErrorEvent objects for various validation and API-related errors, ensuring uniform error reporting.
  • Expanded Error Messages: New, specific error messages have been added to the ERROR_MESSAGE constants for common validation and operational issues, improving clarity.
  • Updated Documentation: The JSDoc for EmbedEvent.Error has been updated to reflect the new structured error object format and provide clearer examples for developers.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines 328 to 343
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);

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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);

Comment on lines 652 to 659
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);

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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);

Comment on lines 664 to 671
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);

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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);

Comment on lines 1315 to 1322
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);

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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);

Comment on lines 215 to 239
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);

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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);

Comment on lines 614 to 630
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);

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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);

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 12, 2025

Open in StackBlitz

npm i https://pkg.pr.new/thoughtspot/visual-embed-sdk/@thoughtspot/visual-embed-sdk@329

commit: b68c845

@shivam-kumar-ts shivam-kumar-ts force-pushed the SCAL-256912 branch 5 times, most recently from 4727f6d to d764c61 Compare October 24, 2025 10:44
@shivam-kumar-ts shivam-kumar-ts force-pushed the SCAL-256912 branch 2 times, most recently from 678e4e4 to b68c845 Compare October 24, 2025 11:54
@sonar-prod-ts
Copy link

sonar-prod-ts bot commented Oct 24, 2025

SonarQube Quality Gate

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

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