-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat(script-compiler): add error responses #75
Changes from 3 commits
4c793fa
cd14cf6
1bc8669
74f6fe2
f2fcc24
1375633
35097e5
e181e81
7ea7580
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,9 +155,15 @@ export const attachToTextArea = ({ | |
// dismiss card before update annotations | ||
// dismissCards(); | ||
const text = textAreaElement.value; | ||
const results = await lintEngine.lintText({ | ||
text | ||
}); | ||
let results; | ||
try { | ||
results = await lintEngine.lintText({ | ||
text | ||
}); | ||
} catch (e) { | ||
debug("lint error", e); | ||
results = [] as const; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Errors should be handled by the caller.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. implemented in e181e81 |
||
debug("lint results", results); | ||
const updateText = async (newText: string, card: TextCheckerCard) => { | ||
const currentText = textAreaElement.value; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to make this just a global error?
Ideally, it would be more convenient if users could get it as a default
error
event in WebWorker.https://developer.mozilla.org/en-US/docs/Web/API/Worker/error_event
Current error handling looks like complex.
If make this just a global error, user can just listen
"error"
event for error handling.📝 Custom Error may be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great for me! But
ErrorEvent.event
seems to be always null.Moreover I found
addEventListener("error", ...)
can handle thrown Error but cannot handle promise rejection. I am considering another idea based on your review.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found
error
event listener can handle promise rejection in the worker if the worker handleunhandledrejection
event and usereportError
.But I haven't found how to handle
id
througherror
event listener.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably,
reportError
allow to reportErrorEvent
which include customError
object.Technically, it could be written as follows.
However, Safari/Node.js/Deno does not support
reportError
in WebWorker yet.https://developer.mozilla.org/en-US/docs/Web/API/reportError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a wip commit f2fcc24 including debug comments to share the situation.
In this case I got a ErrorEvent with
Uncaught #<EventError>
message and null error, soreportError
with ErrorEvent wrapping TextlintError does not work for me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fmm, It may be worker limitation.
We can not pass the details of the error in worker via
error
event.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your information.
Another option for less complex error handling I think is that all errors in the worker are handled through worker messages instead of throwing Error or calling reportError. It seems almost practically safe to omit handling of
error
andmessaageerror
. I finally understand why other libraries such as comlink have their own error message protocol.If we want to promise more safety, worker can post error messages when the worker gets
error
orunhandledrejection
on the worker side:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. it is good that keep it simple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented in 1375633
Textlint worker handles all possible errors and post error messages. It simplified client-side error handling by omitting
error
andmessageerror
event