@@ -186,19 +186,14 @@ export default class FileRepository extends Plugin {
186
186
187
187
// Store also file => loader mapping so loader can be retrieved by file instance returned upon Promise resolution.
188
188
if ( fileOrPromise instanceof Promise ) {
189
- loader . file . then ( file => {
190
- this . _loadersMap . set ( file , loader ) ;
191
- } ) . catch ( ( ) => {
192
- // Catch the file promise rejection. If there are no `catch` clause, the browser
193
- // will throw an error (see https://github.com/ckeditor/ckeditor5-upload/pull/90).
194
- // The error will be handled by `FileLoader` so no action is required here.
195
- } ) ;
196
- } else {
197
- // Catch the file promise rejection. If there are no `catch` clause, the browser
198
- // will throw an error (see https://github.com/ckeditor/ckeditor5-upload/pull/90).
199
- loader . file . catch ( ( ) => {
200
- // The error will be handled by `FileLoader` so no action is required here.
201
- } ) ;
189
+ loader . file
190
+ . then ( file => {
191
+ this . _loadersMap . set ( file , loader ) ;
192
+ } )
193
+ // Every then() must have a catch().
194
+ // File loader state (and rejections) are handled in read() and upload().
195
+ // Also, see the "does not swallow the file promise rejection" test.
196
+ . catch ( ( ) => { } ) ;
202
197
}
203
198
204
199
loader . on ( 'change:uploaded' , ( ) => {
@@ -295,7 +290,7 @@ class FileLoader {
295
290
/**
296
291
* Additional wrapper over the initial file promise passed to this loader.
297
292
*
298
- * @private
293
+ * @protected
299
294
* @member {module:upload/filerepository~FilePromiseWrapper}
300
295
*/
301
296
this . _filePromiseWrapper = this . _createFilePromiseWrapper ( filePromise ) ;
@@ -442,7 +437,7 @@ class FileLoader {
442
437
443
438
this . status = 'reading' ;
444
439
445
- return this . _filePromiseWrapper . promise
440
+ return this . file
446
441
. then ( file => this . _reader . read ( file ) )
447
442
. then ( data => {
448
443
// Edge case: reader was aborted after file was read - double check for proper status.
@@ -495,7 +490,7 @@ class FileLoader {
495
490
496
491
this . status = 'uploading' ;
497
492
498
- return this . _filePromiseWrapper . promise
493
+ return this . file
499
494
. then ( ( ) => this . _adapter . upload ( ) )
500
495
. then ( data => {
501
496
this . uploadResponse = data ;
@@ -521,6 +516,11 @@ class FileLoader {
521
516
this . status = 'aborted' ;
522
517
523
518
if ( ! this . _filePromiseWrapper . isFulfilled ) {
519
+ // Edge case: file loader is aborted before read() is called
520
+ // so it might happen that no one handled the rejection of this promise.
521
+ // See https://github.com/ckeditor/ckeditor5-upload/pull/100
522
+ this . _filePromiseWrapper . promise . catch ( ( ) => { } ) ;
523
+
524
524
this . _filePromiseWrapper . rejecter ( 'aborted' ) ;
525
525
} else if ( status == 'reading' ) {
526
526
this . _reader . abort ( ) ;
@@ -555,7 +555,6 @@ class FileLoader {
555
555
const wrapper = { } ;
556
556
557
557
wrapper . promise = new Promise ( ( resolve , reject ) => {
558
- wrapper . resolver = resolve ;
559
558
wrapper . rejecter = reject ;
560
559
wrapper . isFulfilled = false ;
561
560
@@ -631,9 +630,9 @@ mix( FileLoader, ObservableMixin );
631
630
* Object returned by {@link module:upload/filerepository~FileLoader#_createFilePromiseWrapper} method
632
631
* to add more control over the initial file promise passed to {@link module:upload/filerepository~FileLoader}.
633
632
*
633
+ * @protected
634
634
* @typedef {Object } module:upload/filerepository~FilePromiseWrapper
635
635
* @property {Promise.<File> } promise Wrapper promise which can be chained for further processing.
636
- * @property {Function } resolver Resolves the promise when called.
637
636
* @property {Function } rejecter Rejects the promise when called.
638
637
* @property {Boolean } isFulfilled Whether original promise is already fulfilled.
639
638
*/
0 commit comments