Skip to content

fix: bug toast message for when export default is not present in js object.#36296

Closed
prasad-madine wants to merge 6 commits intoappsmithorg:releasefrom
prasad-madine:fix/bug-fix-toast-message-for-when-export-default-is-not-present-in-js-object-36185
Closed

fix: bug toast message for when export default is not present in js object.#36296
prasad-madine wants to merge 6 commits intoappsmithorg:releasefrom
prasad-madine:fix/bug-fix-toast-message-for-when-export-default-is-not-present-in-js-object-36185

Conversation

@prasad-madine
Copy link
Contributor

@prasad-madine prasad-madine commented Sep 13, 2024

Description:

Fix toast message for when export default is not present in JS Object(Start object with export default).
undefined should not be present in the error message when body of JSObject is emptied and show different toast message JS object must contain 'export default'..

I have raised this PR to fix the toast message for when export default is not present in JSObject and the JSObject is emptied

Fixes #36185

Screenshots:

Before resoving bug:

image

After resoving bug:

When there is no export default:

Screenshot from 2024-09-13 11-25-04

When JSObject is emptied:

Screenshot from 2024-09-13 11-25-13

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced new test cases to validate error handling for empty JavaScript objects and ensure users receive appropriate feedback when the required export syntax is missing.
    • Added new error message functions to enhance clarity regarding JavaScript object export requirements.
  • Bug Fixes

    • Enhanced error messages for JavaScript object creation to provide more specific information about errors, improving user experience during debugging.
    • Simplified error messages for parsing errors to enhance clarity, potentially improving user experience during error handling.

@prasad-madine
Copy link
Contributor Author

Hello @sagar-qa007 @ApekshaBhosale , Could you please review this PR
Thankyou

@rishabhrathod01
Copy link
Contributor

/build-deploy-preview skip-tests=true

@github-actions
Copy link

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

@github-actions
Copy link

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

Copy link
Contributor

@rishabhrathod01 rishabhrathod01 left a comment

Choose a reason for hiding this comment

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

@PrasadMadine For both the error messages could you please remove the at JSObjeect / at JSObject.body.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 13, 2024

Walkthrough

The pull request introduces several changes aimed at enhancing error handling and user feedback related to JavaScript object creation in the application. It adds a new test case to validate the behavior when an empty JavaScript object is provided, ensuring that an appropriate error message is displayed if the required export default statement is missing. Additionally, modifications to the error message construction in the evalErrorHandler function and the saveResolvedFunctionsAndJSUpdates function improve the specificity and clarity of error reporting.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ServerSide/JsFunctionExecution/JSFunctionExecution_spec.ts Added a new test case to validate error handling for empty JavaScript objects, ensuring the correct error message is displayed.
app/client/src/sagas/EvalErrorHandler.ts Modified the error message construction for EvalErrorTypes.PARSE_JS_ERROR to simplify the message by omitting the entity name.
app/client/src/ce/constants/messages.ts Introduced new exported functions for error messages related to JavaScript object exports, enhancing clarity for developers.
app/client/src/workers/Evaluation/JSObject/index.ts Enhanced error handling in saveResolvedFunctionsAndJSUpdates to check if entity.body is empty before generating errors.
app/client/src/workers/Evaluation/JSObject/test.ts Added new test cases for saveResolvedFunctionsAndJSUpdates, validating error messages for empty and incorrectly formatted JS objects.

Assessment against linked issues

Objective Addressed Explanation
Ensure correct error message when JS object is empty (#36185)
Remove undefined from error messages when JS object body is empty (#36185)

Possibly related PRs

Suggested labels

Community Reported, Javascript Product, ok-to-test, Medium

Suggested reviewers

  • sagar-qa007
  • ApekshaBhosale
  • rishabhrathod01

In the realm of code, where errors may roam,
A toast now appears, guiding us home.
With checks in place, and messages clear,
JavaScript objects, we hold dear.
So let’s celebrate this change with glee,
For user feedback, as bright as can be! 🎉


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 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.

@prasad-madine
Copy link
Contributor Author

Hello @rishabhrathod01 , I have addressed the comments, could you please review this PR.
Thankyou

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: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ae5801f and 9e6364c.

Files selected for processing (1)
  • app/client/src/sagas/EvalErrorHandler.ts (1 hunks)
Additional context used
Biome
app/client/src/sagas/EvalErrorHandler.ts

[error] 282-282: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)

Comment on lines +281 to +289
let errorMessage = error.message;
if (!!error.context) {
errorMessage = `${error.message}`;
}
toast.show(errorMessage, {
kind: "error",
});
AppsmithConsole.error({
text: `${error.message} at: ${error.context?.propertyPath}`,
text: `${error.message}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Improved error message construction, but remove redundant double-negation.

Great job simplifying the error message construction based on the presence of error.context! This change enhances clarity by focusing on the core error message when additional context is available.

However, as pointed out by the static analysis hint, the double-negation in the condition !!error.context is redundant. Since the value is already being coerced to a boolean, you can simply use error.context directly in the condition.

Here's the suggested change:

-if (!!error.context) {
+if (error.context) {
  errorMessage = `${error.message}`;
}

This improves code readability without altering the behavior.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let errorMessage = error.message;
if (!!error.context) {
errorMessage = `${error.message}`;
}
toast.show(errorMessage, {
kind: "error",
});
AppsmithConsole.error({
text: `${error.message} at: ${error.context?.propertyPath}`,
text: `${error.message}`,
let errorMessage = error.message;
if (error.context) {
errorMessage = `${error.message}`;
}
toast.show(errorMessage, {
kind: "error",
});
AppsmithConsole.error({
text: `${error.message}`,
Tools
Biome

[error] 282-282: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)

@rishabhrathod01
Copy link
Contributor

/build-deploy-preview skip-tests=true

@github-actions
Copy link

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

@github-actions
Copy link

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

@prasad-madine
Copy link
Contributor Author

Hello @sagar-qa007 , I have added the unit test cases, could you please review this PR.

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

Outside diff range and nitpick comments (1)
app/client/src/ce/constants/messages.ts (1)

Line range hint 12-24: Let's rethink the flat fee logic

The discount percentages based on loyalty years look good. However, I'm not sure about always adding a flat $20 fee to the discounted amount. For smaller purchases, this could actually make the final bill more expensive than the original price, even with the discount!

For example, let's say a customer has been loyal for 3 years and makes a $100 purchase.

  • They qualify for a 10% discount, making the discounted price $90
  • But then we add the $20 flat fee, so their final bill is $110. That's more than the original price of $100!

This might discourage customers from using the loyalty discount, especially those making smaller purchases or those who barely qualify for a discount tier.

I'd suggest we reconsider the flat fee and make sure the discount logic always results in some savings for the customer. Perhaps we could do a percentage-based fee instead, or only apply the fee for purchases over a certain amount. What do you think?

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9e6364c and 4161ef0.

Files selected for processing (3)
  • app/client/src/ce/constants/messages.ts (1 hunks)
  • app/client/src/workers/Evaluation/JSObject/index.ts (2 hunks)
  • app/client/src/workers/Evaluation/JSObject/test.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/workers/Evaluation/JSObject/index.ts
Additional comments not posted (2)
app/client/src/workers/Evaluation/JSObject/test.ts (2)

140-160: Excellent work on this test case!

This test case is well-structured and effectively verifies the behavior of the saveResolvedFunctionsAndJSUpdates function when the JSObject is empty. It correctly asserts that the appropriate toast message is raised, indicating that the JS object must contain 'export default'.

The use of a mocked function to capture the toast message is a great approach, as it allows for precise assertions on the expected message content and properties.

Keep up the good work in ensuring the robustness of the error handling logic!


161-181: Great job on this test case!

This test case effectively validates the behavior of the saveResolvedFunctionsAndJSUpdates function when the JSObject body starts with the keyword "export". It ensures that the appropriate toast message is raised, instructing the user to start the object with "export default".

The test case follows a similar structure to the previous one, mocking the errors.push function to capture and assert on the raised toast message. This consistency in the test structure makes the test suite more readable and maintainable.

Your attention to detail in handling different scenarios and providing informative error messages enhances the user experience and helps in identifying and resolving issues quickly.

Well done on this test case!

@rishabhrathod01
Copy link
Contributor

@PrasadMadine could please resolve the merge conflict with the release branch on this PR?

…to fix/bug-fix-toast-message-for-when-export-default-is-not-present-in-js-object-36185
@prasad-madine
Copy link
Contributor Author

Hello @rishabhrathod01 , I have resolved the conflicts and updated the PR.

@prasad-madine
Copy link
Contributor Author

Hello @rishabhrathod01 , Could you please review this PR.

@rishabhrathod01
Copy link
Contributor

@PrasadMadine This is in our review pipeline and will be picked up soon.

@rishabhrathod01
Copy link
Contributor

@PrasadMadine Please resolve the merge conflict with the latest release branch.

…to fix/bug-fix-toast-message-for-when-export-default-is-not-present-in-js-object-36185
@prasad-madine
Copy link
Contributor Author

@rishabhrathod01 Resolved the conflicts and updated the PR
Thankyou.

@rishabhrathod01 rishabhrathod01 added Bug Something isn't working JS Objects Issues related to JS Objects Query & JS Pod Issues related to the query & JS Pod Community Contributor Meant to track issues that are assigned to external contributors Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. labels Sep 30, 2024
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: 1

🧹 Outside diff range and nitpick comments (1)
app/client/src/workers/Evaluation/JSObject/test.ts (1)

164-184: Excellent work! This test case deserves a spot on our class bulletin board.

I'm thrilled to see this additional test case. It's like you've solved another part of our coding puzzle:

  1. You've prepared your mock function again (always start with a clean slate!).
  2. You've called our function with a different input (trying a new approach).
  3. You've made sure your mock function was called (checking for that 'aha!' moment).
  4. You've verified the specific error message (making sure you got the right answer).

This test complements the first one beautifully, giving us a more complete picture. However, let's make one small improvement for consistency:

Consider adding show: false, to the expected error object, just like in the first test case. This ensures our tests are uniform:

 expect(mockFunction).toHaveBeenCalledWith({
   type: "PARSE_JS_ERROR",
   context: {
     entity: { body: "export" },
     propertyPath: "JSObject1.body",
   },
   message: "Start object with export default",
+  show: false,
 });

Keep up this excellent attention to detail!

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5c02876 and 0dc86b0.

📒 Files selected for processing (3)
  • app/client/src/sagas/EvalErrorHandler.ts (1 hunks)
  • app/client/src/workers/Evaluation/JSObject/index.ts (2 hunks)
  • app/client/src/workers/Evaluation/JSObject/test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/src/workers/Evaluation/JSObject/index.ts
🧰 Additional context used
🪛 Biome
app/client/src/sagas/EvalErrorHandler.ts

[error] 292-292: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)

🔇 Additional comments (3)
app/client/src/workers/Evaluation/JSObject/test.ts (2)

142-163: Well done, class! This test case is a gold star example.

I'm pleased to see this new test case. It's like solving a tricky math problem step by step:

  1. You've set up your mock function (think of it as your scratch paper).
  2. You've called the function we're testing (that's like writing out the equation).
  3. You've checked if your mock function was called (did you get an answer?).
  4. Finally, you've verified the content of the error message (is the answer correct?).

This test aligns perfectly with our lesson objective of fixing the toast message when export default is missing. Keep up the good work!


142-184: Class, let's give a round of applause for these excellent additions!

These new test cases are like well-crafted essays that address our main topic perfectly. They thoroughly examine the behavior of our saveResolvedFunctionsAndJSUpdates function in different scenarios:

  1. When the JSObject is empty (lines 142-163)
  2. When the JSObject body starts with "export" but doesn't have "default" (lines 164-184)

These tests align beautifully with our lesson objective of fixing the toast message for when export default is not present in a JS Object. They ensure that:

  • An appropriate message is displayed when the JS object is empty.
  • A specific message is shown when the object starts with "export" but is missing "default".

By adding these tests, you've not only fixed the issue but also ensured that it stays fixed in the future. It's like you've not just solved the problem, but also created a study guide for future students!

Great job addressing the objectives outlined in issue #36185. Your attention to detail and thorough testing approach deserve top marks!

app/client/src/sagas/EvalErrorHandler.ts (1)

290-300: Let's summarize our lesson on error handling, class.

Today, we've learned about improving our error messages in the PARSE_JS_ERROR case. Here's what we've accomplished:

  1. We've simplified our error message construction, making it more concise and easier for users to understand.
  2. We've ensured consistency between the toast notification and console log, which is crucial for effective debugging.
  3. We've identified and corrected a small redundancy in our code, demonstrating the importance of clean, efficient programming.

These changes align well with our lesson objectives of creating clear, user-friendly error messages and maintaining code quality. Well done, everyone!

Remember, clear error messages are like good directions - they help users and developers find their way when things go wrong. Keep up the good work!

🧰 Tools
🪛 Biome

[error] 292-292: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)

Comment on lines +290 to +296
let errorMessage = error.message;

if (!!error.context) {
errorMessage = `${error.message}`;
}

toast.show(errorMessage, {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Class, let's examine the changes in our error handling.

Now, students, I want you to pay close attention to how we've simplified our error message construction. This is a good step towards clarity, but we have a small issue to address.

  1. The simplification of the error message is commendable. We've removed the entity name from the context, focusing solely on the error message itself. This can make the error more concise and easier to understand.

  2. However, we have a little redundancy in our code. Can anyone spot it? Yes, you in the back! That's right, the double negation in the condition !!error.context is unnecessary. Remember, class, JavaScript will automatically coerce the value to a boolean in an if statement. Let's clean that up.

  3. Lastly, notice how we're now using the same error message for both the toast notification and the console log. Consistency is key in error reporting, children!

Let's make a small correction to improve our code:

-if (!!error.context) {
+if (error.context) {
  errorMessage = `${error.message}`;
}

This change will make our code cleaner and easier to read. Remember, class, always strive for clarity and simplicity in your code!

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let errorMessage = error.message;
if (!!error.context) {
errorMessage = `${error.message}`;
}
toast.show(errorMessage, {
let errorMessage = error.message;
if (error.context) {
errorMessage = `${error.message}`;
}
toast.show(errorMessage, {
🧰 Tools
🪛 Biome

[error] 292-292: Avoid redundant double-negation.

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

(lint/complexity/noExtraBooleanCast)

@rishabhrathod01
Copy link
Contributor

@PrasadMadine could you please check and fix the type error here https://github.com/appsmithorg/appsmith/actions/runs/11261876012/job/31316293444?pr=36790 that is leading to build failure.

@rohan-arthur
Copy link
Contributor

rohan-arthur commented Oct 14, 2024

@PrasadMadine we will wait until 17 Oct, and move this back to the backlog if there are no further updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Community Contributor Meant to track issues that are assigned to external contributors Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Integrations Pod JS Objects Issues related to JS Objects Query & JS Pod Issues related to the query & JS Pod

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Fix toast message for when export default is not present in JS Object

6 participants