Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,16 @@ return "yes";`;
entityType: entityItems.JSObject,
});
});
it("11. Should throw an error when JS Object is empty", () => {
Comment thread
prasad-madine marked this conversation as resolved.
Outdated
const jsObjectEmptyToastMessage =
"JS object must contain 'export default'.";
jsEditor.CreateJSObject(` `, {
paste: true,
completeReplace: true,
toRun: false,
prettify: false,
});

agHelper.AssertContains(jsObjectEmptyToastMessage);
});
});
6 changes: 5 additions & 1 deletion app/client/src/sagas/EvalErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ export function* evalErrorHandler(
break;
}
case EvalErrorTypes.PARSE_JS_ERROR: {
toast.show(`${error.message} at: ${error.context?.entity.name}`, {
let errorMessage = error.message;
if (!!error.context) {
errorMessage = `${error.message} at: ${error.context?.propertyPath}`;
}
toast.show(errorMessage, {
Comment on lines +290 to +296

Copy link
Copy Markdown
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)

kind: "error",
});
AppsmithConsole.error({
Expand Down
31 changes: 22 additions & 9 deletions app/client/src/workers/Evaluation/JSObject/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,28 @@ export function saveResolvedFunctionsAndJSUpdates(
}

if (!correctFormat && !isUndefined(entity.body)) {
const errors = {
type: EvalErrorTypes.PARSE_JS_ERROR,
context: {
entity: entity,
propertyPath: entityName + ".body",
},
message: "Start object with export default",
};
dataTreeEvalRef.errors.push(errors);
if (entity.body.trim() !== "") {
const errors = {
type: EvalErrorTypes.PARSE_JS_ERROR,
context: {
entity: entity,
propertyPath: entityName + ".body",
},
message: "Start object with export default",
Comment thread
prasad-madine marked this conversation as resolved.
Outdated
};
dataTreeEvalRef.errors.push(errors);
} else {
const errors = {
type: EvalErrorTypes.PARSE_JS_ERROR,
context: {
entity: entity,
propertyPath: entityName,
},
message: "JS object must contain 'export default'.",
show: false,
};
dataTreeEvalRef.errors.push(errors);
}
}

return jsUpdates;
Expand Down