-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Wrap popular parts of the code into try-catch block #1304
Comments
Firstly I'll check if the |
I've checked it and |
❤️ |
I think that we should also make sure that all of the async code is wrapped (promises has catch block which wraps errors in CKEditor error class). |
Do we have promises somewhere except the editor initialization? |
Upload adapter? You can look for |
There are some native listeners added here (via Also, I'd expect to find some things via searching for But most of those things are not worth covering. In fact, an error in such a listener usually doesn't crash the app. From things that I know that were causing issues I can mention the upload stuff. There are promisses there and a quite complicated logic that caused some issues for us recently. But here... touching these parts without analysing the logic can actually break them unless you're considering throwing from |
There's also a huge list of listeners in the UI. But I guess this is also beyond the things that are worth watching. |
I have some doubts about the implementation. First I was thinking about something like this: try {
// Some CKEditor 5 code.
} catch ( err ) {
if ( err.is && err.is( 'CKEditorError' ) ) {
throw err;
}
throw new CKEditorError( 'model-change-unexpected-error', this, {
originalError: {
message: err.message,
stack: err.stack,
name: err.name
}
} );
} But now I feel this approach would increase the code size significantly if we implement these It could be called |
In fact, the only part which changes is the message so maybe:
Or, alternately, we can take the message from |
On the second thought, I think that overwriting error messages may hide the real reason of the error and make the console less readable, so I think we should not overwrite the error message, and your proposal |
I'm not sure if it should be I'd propose e.g. try {
// Some CKEditor 5 code.
} catch ( err ) {
CKEditorError.rethrowUnexpectedError( err, context );
} Other possible method names could be related to "enhancing" or "rethrow as", etc. |
I'm fine with this approach too and the name fits well. |
Docs: Aligned docs to added try-catch blocks. Part of ckeditor/ckeditor5#1304.
Other: Introduced the `CKEditorError.rethrowUnexpectedError()` helper. Added custom error handling for the `Emitter#fire()` function. Part of ckeditor/ckeditor5#1304.
Tests: Changed test assertion as it should throw now the `unexpected-error` error. Part of ckeditor/ckeditor5#1304.
Other: Added error handling to the common code execution paths. Part of ckeditor/ckeditor5#1304.
Other: Added custom error handling to the `editor.execute()` method. Part of ckeditor/ckeditor5#1304.
We could wrap some popular places where error can occur in the try-catch to replace a generic exception to the CKEditor 5 specific one. Such specific error could be later caught to restart the editor.
Some places we could add such try-catch blocks:
engine.model.change
,engine.view.change
,engine.transformSets
,core.command.execute
,engine.view.observer
events.The text was updated successfully, but these errors were encountered: