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)
Open Source Security 0 0 0 0 0 issues
Licenses 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: 1d83508

@shivam-kumar-ts shivam-kumar-ts force-pushed the SCAL-256912 branch 8 times, most recently from b68c845 to 3301d3e Compare October 29, 2025 06:04
@shivam-kumar-ts shivam-kumar-ts force-pushed the SCAL-256912 branch 2 times, most recently from fa1049d to 7b478a3 Compare November 5, 2025 01:54
});
// Log error
logger.error(error);
logger.error(errorDetails);
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove this.

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;
Copy link
Contributor

@adityamittal3107 adityamittal3107 Nov 5, 2025

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

use enum

Copy link
Contributor

Choose a reason for hiding this comment

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

dont allow string

Copy link
Contributor Author

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';
Copy link
Contributor

Choose a reason for hiding this comment

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

enum

Copy link
Contributor Author

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;
Copy link
Contributor

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

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

Copy link
Contributor Author

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

errorType: 'VALIDATION_ERROR',
message: ERROR_MESSAGE.CONFLICTING_ACTIONS_CONFIG,
code: ERROR_CODE.CONFLICTING_ACTIONS_CONFIG,
source: 'SDK',
Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

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';
Copy link
Contributor

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 ?

Copy link
Contributor Author

@shivam-kumar-ts shivam-kumar-ts Nov 7, 2025

Choose a reason for hiding this comment

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

No, source give the information of that in come from api or sdk

image

Copy link
Contributor

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 ?

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

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

code: ERROR_CODE.INIT_ERROR,
source: ErrorDetailsSources.SDK,
details: {},
} as EmbedErrorDetailsEvent);
Copy link
Contributor

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',
Copy link
Contributor

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
Comment on lines 6157 to 6158
export enum ErrorDetailsSources {
API = 'API',
Copy link
Contributor

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
Copy link
Contributor

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.

@sonar-prod-ts
Copy link

sonar-prod-ts bot commented Nov 22, 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.

5 participants