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: #2960 type error #3066

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

JerryWu1234
Copy link
Contributor

@JerryWu1234 JerryWu1234 commented Jan 9, 2024

#2960

  • I've read and followed the contributing guide on how to create great pull requests.
  • I've updated the relevant documentation for any new or updated feature.
  • I've linked relevant GitHub issue with "Closes #".
  • I've added a visual demonstration in the form of a screenshot or video.

@JerryWu1234
Copy link
Contributor Author

image
image

@JerryWu1234
Copy link
Contributor Author

@Janpot
There is a slight conflict because you want to print the error message in the Toolpad CLI. It cannot concurrently ask the user whether they want to save the content because the error message has already been intercepted by the try-catch block in the backend.

If you want to achieve this goal, I suggest invoking the applyDomDiff after detecting the error. This way, we can ensure that the frontend has already received an error message

@JerryWu1234 JerryWu1234 marked this pull request as ready for review January 16, 2024 03:15
@zannager zannager added the bug 🐛 Something doesn't work label Jan 18, 2024
@JerryWu1234
Copy link
Contributor Author

@Janpot please review

@@ -980,6 +980,7 @@ export default function AppProvider({ appUrl, children }: DomContextProps) {
dispatch({ type: 'DOM_SAVED', savedDom: domToSave });
})
.catch((err) => {
console.error(err.message);
Copy link
Member

@Janpot Janpot Feb 27, 2024

Choose a reason for hiding this comment

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

Let's give users some context

Suggested change
console.error(err.message);
console.error(`Failed to save the dom: ${err.message}`);

Copy link
Member

@Janpot Janpot Feb 27, 2024

Choose a reason for hiding this comment

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

How do you feel about the following

  • when we detect that prettier errored, we show a confirmation dialog "prettier failed with error X, do you want to save without formatting".
  • this sets a ignoreFormattingErrors to the state
  • add a force: boolean option to applyDomDiff which tries to prettify but ignores errors, we call it with:
    applyDomDiff(state.dom, { force: state.ignoreFormattingErrors })

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me try

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when we detect that prettier errored, we show confirmation a dialog "prettier failed with error X, do you want to save without formatting".

how to display this dialog ? if a format error is detected, this dialog will be always displayed
is there a strategy for this dialog?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

if a format error is detected, this dialog will be always displayed
is there a strategy for this dialog?

If a user confirms the dialog, then ignoreFormattingErrors will get set in the state, and the next time applyDomDiff is called it will get a force: true value and shouldn't error on formatting errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about the ignoreFormattingErrors gets false? we don't do anything?

Copy link
Member

@Janpot Janpot Mar 12, 2024

Choose a reason for hiding this comment

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

We don't leave that option open. You either confirm or fix your setup. i.e. We say:

Failed to save because of an error in your formatter:
{error message}
Click Ignore to save without formatting, or "Retry" to try again.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 9, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants