Skip to content
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

fix: Enhance error handling in ComputeTablePropertyControlV2 binding methods #38205

Open
wants to merge 7 commits into
base: release
Choose a base branch
from

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Dec 17, 2024

Description

Updated the binding methods in ComputeTablePropertyControlV2 to improve error handling. The binding prefix now includes a try-catch block to prevent runtime errors when processing table data, ensuring that null values are returned gracefully in case of exceptions.

Fixes #38157
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Table"

🔍 Cypress test results

Caution

🔴 🔴 🔴 Some tests have failed.
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12515152114
Commit: 36d974f
Cypress dashboard.
Tags: @tag.Table
Spec:
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_Derived_Column_Data_validation_spec.js
List of identified flaky tests.
Fri, 27 Dec 2024 11:45:09 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced error handling in the binding logic for improved robustness.
    • Improved type safety in data transformation processes.
    • Introduced new migration functionality for handling computed values in table widgets.
  • Bug Fixes

    • Resolved potential runtime errors during binding expression evaluation.
  • Tests

    • Added new test cases to validate error handling in computed values and migration functionality.
  • Documentation

    • Updated method signatures and variable types for clarity and consistency.

…methods

Updated the binding methods in `ComputeTablePropertyControlV2` to improve error handling. The binding prefix now includes a try-catch block to prevent runtime errors when processing table data, ensuring that null values are returned gracefully in case of exceptions.
@rahulbarwal rahulbarwal requested a review from a team as a code owner December 17, 2024 08:09
Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Walkthrough

The pull request introduces enhancements to error handling in the ComputeTablePropertyControlV2 class within TableComputeValue.tsx, specifically in the methods for generating binding prefixes and suffixes. It also updates the type definition for the newRow variable in transformDataPureFn.tsx to improve type safety. Additionally, a new migration function is added to manage computed values in table widgets, ensuring that missing properties do not result in JSON data being displayed in table cells.

Changes

File Change Summary
app/client/src/components/propertyControls/TableComputeValue.tsx Enhanced error handling in getBindingPrefix and bindingSuffix methods
app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/transformDataPureFn.tsx Updated newRow type from any to unknown for improved type safety
app/client/packages/dsl/src/migrate/index.ts Added migrateTableWidgetV2ValidationTryCatch function and updated LATEST_DSL_VERSION to 91
app/client/packages/dsl/src/migrate/migrations/090-migrate-table-widget-v2-validation-try-catch.ts Introduced migration function to update computed values with error handling
app/client/packages/dsl/src/migrate/tests/DSLMigration.test.ts Integrated new migration function into the migration tests
app/client/packages/dsl/src/migrate/tests/TableWidgetV2/DSLs/ValidationTryCatchDSLs.ts Added constants for validation input and output with error handling
app/client/packages/dsl/src/migrate/tests/TableWidgetV2/ValidationTryCatch.test.ts Created new tests for the migration function to validate error handling

Assessment against linked issues

Objective Addressed Explanation
Prevent JSON display for missing values [#38157]
Handle undefined values in computed columns The changes include error handling that addresses this issue.

Possibly related PRs

Suggested labels

Enhancement, Backend, Packages Pod, Tech Debt

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007
  • jsartisan

Poem

In code we trust, with care we bind,
Errors caught, no more to find.
Types defined, our safety net,
In tables clear, no more regret.
With every test, our spirits soar,
Robust and bright, we code for more! 🎉✨

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added Bug Something isn't working Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production Table Widget V2 Issues related to Table Widget V2 Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets labels Dec 17, 2024
@rahulbarwal rahulbarwal marked this pull request as draft December 17, 2024 08:09
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12368869711.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 38205.
recreate: .

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/client/src/components/propertyControls/TableComputeValue.tsx (1)

106-106: Consider logging errors before returning null

While returning null is a good fallback, silently swallowing errors might make debugging harder.

Consider adding error logging:

-  static bindingSuffix = `); } catch (e) { return null; }})}}`;
+  static bindingSuffix = `); } catch (e) { console.error('Table computation error:', e); return null; }})}}`;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d905a4c and 2a202cb.

📒 Files selected for processing (2)
  • app/client/src/components/propertyControls/TableComputeValue.tsx (1 hunks)
  • app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/transformDataPureFn.tsx (1 hunks)
🔇 Additional comments (3)
app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/transformDataPureFn.tsx (1)

19-19: Good type safety improvement!

Changing from any to unknown enforces better type checking and reduces potential runtime errors.

app/client/src/components/propertyControls/TableComputeValue.tsx (2)

103-103: Good addition of try block for error isolation

The try block ensures that errors in one row's computation don't affect other rows.


103-106: Verify impact on existing error handling

The new error handling affects all computed values. Let's verify there are no duplicate error handlers or logging.

✅ Verification successful

Let me analyze the error handling patterns in the codebase to verify if there are any duplicate handlers or logging conflicts.


Error handling implementation is appropriate

The error handling in TableComputeValue.tsx is correctly implemented and doesn't conflict with other error handlers. The catch block returns null for computation errors, while other handlers in the table widget ecosystem handle specific scenarios (date parsing, local data reading, etc.) with appropriate logging.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing error handling in table computation code
rg -A 2 "catch \(e\)" --type ts

Length of output: 65866


Script:

#!/bin/bash
# Search for error handling in table computation and related files
rg -A 2 "catch \(e\)" --type ts app/client/src/components/propertyControls/TableComputeValue.tsx app/client/src/widgets/TableWidgetV2/widget/utilities.ts app/client/src/widgets/TableWidgetV2/widget/propertyUtils.ts app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/transformDataPureFn.tsx

Length of output: 2546

Copy link

Deploy-Preview-URL: https://ce-38205.dp.appsmith.com

@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12373445425.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 38205.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-38205.dp.appsmith.com

Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Dec 24, 2024
…o rahulbarwal/issue38157/Bug-JSON-values-are-shown-in-the-table-cell-when-one-of-the-rows-does-not-contain-corresponding-value
- Introduced a new migration (090) to update computed value bindings in TABLE_WIDGET_V2 to include try-catch blocks for error handling.
- Updated LATEST_DSL_VERSION to 91 to reflect the new migration.
- Added tests to ensure the migration correctly modifies the computed values as expected.
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@rahulbarwal rahulbarwal added the ok-to-test Required label for CI label Dec 26, 2024
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12503447032.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 38205.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-38205.dp.appsmith.com

@github-actions github-actions bot removed the Stale label Dec 26, 2024
…perties

- Introduced a new test case to verify that computed values in TableV2 correctly handle missing nested properties using try-catch blocks.
- The test checks the behavior of the table when provided with data containing nested objects and missing properties, ensuring that it returns expected values or empty strings as appropriate.
@rahulbarwal rahulbarwal self-assigned this Dec 27, 2024
@rahulbarwal rahulbarwal marked this pull request as ready for review December 27, 2024 10:50
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/client/packages/dsl/src/migrate/tests/TableWidgetV2/DSLs/ValidationTryCatchDSLs.ts (2)

16-31: Consider removing as any type casting.
Using a more specific type definition for validationTryCatchInput will help improve type safety.

-} as any as DSLWidget;
+} as DSLWidget;

33-48: Similarly, refine type definition for validationTryCatchOutput.
Maintaining strict typing helps catch errors earlier.

-} as any as DSLWidget;
+} as DSLWidget;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a202cb and 36d974f.

📒 Files selected for processing (6)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_Derived_Column_Data_validation_spec.js (1 hunks)
  • app/client/packages/dsl/src/migrate/index.ts (2 hunks)
  • app/client/packages/dsl/src/migrate/migrations/090-migrate-table-widget-v2-validation-try-catch.ts (1 hunks)
  • app/client/packages/dsl/src/migrate/tests/DSLMigration.test.ts (2 hunks)
  • app/client/packages/dsl/src/migrate/tests/TableWidgetV2/DSLs/ValidationTryCatchDSLs.ts (1 hunks)
  • app/client/packages/dsl/src/migrate/tests/TableWidgetV2/ValidationTryCatch.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_Derived_Column_Data_validation_spec.js (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
🔇 Additional comments (8)
app/client/packages/dsl/src/migrate/tests/TableWidgetV2/ValidationTryCatch.test.ts (1)

1-15: LGTM!
The test effectively verifies that try-catch blocks are inserted into the computed values.

app/client/packages/dsl/src/migrate/migrations/090-migrate-table-widget-v2-validation-try-catch.ts (1)

15-46: Overall approach is aligned with migration best practices.
The code properly verifies matching prefixes before updating to the new error-handling variant.

app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_Derived_Column_Data_validation_spec.js (1)

125-128: ⚠️ Potential issue

Fix possible mustache brace mismatch in table data.
It appears there's a missing closing curly brace. This might cause the expression to fail.

-propPane.UpdatePropertyFieldValue(
-  "Table data",
-  `{{[{"name": "Rahul", age: {value: 31}}, {"name": "Jacq", age: {}}, {"name": "John"}]}`
-);
+propPane.UpdatePropertyFieldValue(
+  "Table data",
+  `{{[{"name": "Rahul", age: {value: 31}}, {"name": "Jacq", age: {}}, {"name": "John"}]}}`
+);

Likely invalid or redundant comment.

app/client/packages/dsl/src/migrate/index.ts (3)

94-94: New migration import is consistent.
This import correctly integrates the new migration function into the existing migration framework.


97-97: DSL version increment aligns with new migration.
Updating LATEST_DSL_VERSION to 91 properly reflects the addition of the new migration step.


617-621: Ensures version 90 is handled with new try-catch logic.
These lines correctly insert the new migration step into the versioned DSL flow. This adds robust error handling for table widget validations and ensures a seamless jump to the latest version.

app/client/packages/dsl/src/migrate/tests/DSLMigration.test.ts (2)

93-93: Accurate import of new migration module.
Importing m90 ensures the test suite can reference the new migration function.


934-942: Properly adds the new migration function to the test sequence.
Including the migrateTableWidgetV2ValidationTryCatch entry at version 90 maintains synchronization with the production migration logic.

Copy link

github-actions bot commented Jan 3, 2025

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production Stale Table Widget V2 Issues related to Table Widget V2 Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: JSON values are shown in the table cell, when one of the rows does not contain corresponding value.
1 participant