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 many lurking undefined errors #5399

Merged
merged 4 commits into from
Aug 15, 2024
Merged

Fix many lurking undefined errors #5399

merged 4 commits into from
Aug 15, 2024

Conversation

mifi
Copy link
Contributor

@mifi mifi commented Aug 9, 2024

there was an assumption that assembly is required and is never undefined even though it is typed as optional and assigned to undefined in onError

there was an assumption that assembly is required and is never undefined
even though it is typed as optional and assigned to undefined in onError
Copy link
Contributor

github-actions bot commented Aug 9, 2024

Diff output files
diff --git a/packages/@uppy/transloadit/lib/index.js b/packages/@uppy/transloadit/lib/index.js
index bff7087..58d2664 100644
--- a/packages/@uppy/transloadit/lib/index.js
+++ b/packages/@uppy/transloadit/lib/index.js
@@ -152,6 +152,7 @@ export default class Transloadit extends BasePlugin {
     Object.defineProperty(this, _onCancelAll, {
       writable: true,
       value: async () => {
+        if (!this.assembly) return;
         try {
           await _classPrivateFieldLooseBase(this, _cancelAssembly)[_cancelAssembly](this.assembly.status);
         } catch (err) {
@@ -223,7 +224,8 @@ export default class Transloadit extends BasePlugin {
           _classPrivateFieldLooseBase(this, _connectAssembly)[_connectAssembly](this.assembly);
         };
         const updateAssemblies = () => {
-          return this.assembly.update();
+          var _this$assembly;
+          return (_this$assembly = this.assembly) == null ? void 0 : _this$assembly.update();
         };
         this.restored = Promise.resolve().then(() => {
           restoreState();
@@ -245,9 +247,9 @@ export default class Transloadit extends BasePlugin {
         (_assemblyOptions$fiel = assemblyOptions.fields) != null ? _assemblyOptions$fiel : assemblyOptions.fields = {};
         validateParams(assemblyOptions.params);
         try {
-          var _this$assembly;
-          const assembly = (_this$assembly = this.assembly) != null
-            ? _this$assembly
+          var _this$assembly2;
+          const assembly = (_this$assembly2 = this.assembly) != null
+            ? _this$assembly2
             : await _classPrivateFieldLooseBase(this, _createAssembly)[_createAssembly](fileIDs, assemblyOptions);
           if (this.opts.importFromUploadURLs) {
             await _classPrivateFieldLooseBase(this, _reserveFiles)[_reserveFiles](assembly, fileIDs);
@@ -273,6 +275,7 @@ export default class Transloadit extends BasePlugin {
     Object.defineProperty(this, _afterUpload, {
       writable: true,
       value: (fileIDs, uploadID) => {
+        var _this$assembly3;
         const files = fileIDs.map(fileID => this.uppy.getFile(fileID));
         const filteredFileIDs = files.filter(file => !file.error).map(file => file.id);
         if (this.restored) {
@@ -280,15 +283,20 @@ export default class Transloadit extends BasePlugin {
             return _classPrivateFieldLooseBase(this, _afterUpload)[_afterUpload](filteredFileIDs, uploadID);
           });
         }
-        const assemblyID = this.assembly.status.assembly_id;
+        const assemblyID = (_this$assembly3 = this.assembly) == null ? void 0 : _this$assembly3.status.assembly_id;
         const closeSocketConnections = () => {
-          this.assembly.close();
+          var _this$assembly4;
+          (_this$assembly4 = this.assembly) == null || _this$assembly4.close();
         };
         if (!_classPrivateFieldLooseBase(this, _shouldWaitAfterUpload)[_shouldWaitAfterUpload]()) {
+          var _this$assembly5;
           closeSocketConnections();
-          this.uppy.addResultData(uploadID, {
-            transloadit: [this.assembly.status],
-          });
+          const status = (_this$assembly5 = this.assembly) == null ? void 0 : _this$assembly5.status;
+          if (status != null) {
+            this.uppy.addResultData(uploadID, {
+              transloadit: [status],
+            });
+          }
           return Promise.resolve();
         }
         if (!assemblyID) {
@@ -305,18 +313,22 @@ export default class Transloadit extends BasePlugin {
           });
         });
         return _classPrivateFieldLooseBase(this, _watcher)[_watcher].promise.then(() => {
+          var _this$assembly6;
           closeSocketConnections();
-          this.uppy.addResultData(uploadID, {
-            transloadit: [this.assembly.status],
-          });
+          const status = (_this$assembly6 = this.assembly) == null ? void 0 : _this$assembly6.status;
+          if (status != null) {
+            this.uppy.addResultData(uploadID, {
+              transloadit: [status],
+            });
+          }
         });
       },
     });
     Object.defineProperty(this, _closeAssemblyIfExists, {
       writable: true,
       value: () => {
-        var _this$assembly2;
-        (_this$assembly2 = this.assembly) == null || _this$assembly2.close();
+        var _this$assembly7;
+        (_this$assembly7 = this.assembly) == null || _this$assembly7.close();
       },
     });
     Object.defineProperty(this, _onError, {
@@ -414,7 +426,8 @@ export default class Transloadit extends BasePlugin {
     });
   }
   getAssembly() {
-    return this.assembly.status;
+    var _this$assembly8;
+    return (_this$assembly8 = this.assembly) == null ? void 0 : _this$assembly8.status;
   }
   getAssemblyFiles(assemblyID) {
     return this.uppy.getFiles().filter(file => {
@@ -632,10 +645,10 @@ function _onResult2(assemblyId, stepName, result) {
   });
   this.uppy.emit("transloadit:result", stepName, result, this.getAssembly());
 }
-function _onAssemblyFinished2(status) {
-  const url = status.assembly_ssl_url;
+function _onAssemblyFinished2(assembly) {
+  const url = assembly.status.assembly_ssl_url;
   this.client.getAssemblyStatus(url).then(finalStatus => {
-    this.assembly.status = finalStatus;
+    assembly.status = finalStatus;
     this.uppy.emit("transloadit:complete", finalStatus);
   });
 }
@@ -678,11 +691,11 @@ function _connectAssembly2(assembly) {
   }
   if (this.opts.waitForEncoding) {
     assembly.on("finished", () => {
-      _classPrivateFieldLooseBase(this, _onAssemblyFinished)[_onAssemblyFinished](assembly.status);
+      _classPrivateFieldLooseBase(this, _onAssemblyFinished)[_onAssemblyFinished](assembly);
     });
   } else if (this.opts.waitForMetadata) {
     assembly.on("metadata", () => {
-      _classPrivateFieldLooseBase(this, _onAssemblyFinished)[_onAssemblyFinished](assembly.status);
+      _classPrivateFieldLooseBase(this, _onAssemblyFinished)[_onAssemblyFinished](assembly);
     });
   }
   if (assembly.ok === "ASSEMBLY_COMPLETE") {

@aduh95 aduh95 merged commit f70e14a into main Aug 15, 2024
17 checks passed
@aduh95 aduh95 deleted the null-assertion-fixes branch August 15, 2024 17:35
github-actions bot added a commit that referenced this pull request Aug 16, 2024
| Package                | Version | Package                | Version |
| ---------------------- | ------- | ---------------------- | ------- |
| @uppy/aws-s3           |   4.0.3 | @uppy/provider-views   |   4.0.1 |
| @uppy/companion        |   5.0.5 | @uppy/status-bar       |   4.0.2 |
| @uppy/companion-client |   4.0.1 | @uppy/transloadit      |   4.0.2 |
| @uppy/core             |   4.1.1 | @uppy/tus              |   4.0.1 |
| @uppy/dashboard        |   4.0.3 | @uppy/utils            |   6.0.2 |
| @uppy/drag-drop        |   4.0.2 | @uppy/vue              |   2.0.1 |
| @uppy/file-input       |   4.0.1 | uppy                   |   4.1.1 |
| @uppy/image-editor     |   3.0.1 |                        |         |

- @uppy/transloadit: fix issue with `allowMultipleUploadBatches` (Mikael Finstad / #5400)
- meta: Bump elliptic from 6.5.5 to 6.5.7 (dependabot[bot] / #5410)
- meta: add back patch for `p-queue` (Antoine du Hamel / #5409)
- @uppy/transloadit: fix many lurking `TypeError` (Mikael Finstad / #5399)
- docs: improve `corsOrigins` documentation (Mikael Finstad / #5390)
- docs: add `ViewEncapsulation` to Angular example (Aaron Russell / #5395)
- @uppy/companion: fix code for custom providers (Mikael Finstad / #5398)
- docs: add note about throwing in `cancelAll` and `destroy()` (Mikael Finstad / #5408)
- meta: Bump docker/login-action from 3.2.0 to 3.3.0 (dependabot[bot] / #5372)
- meta: Bump docker/setup-qemu-action from 3.1.0 to 3.2.0 (dependabot[bot] / #5370)
- docs: make hosted Companion more clear (Merlijn Vos / #5394)
- meta: Bump docker/build-push-action from 6.4.1 to 6.6.1 (dependabot[bot] / #5403)
- meta: bump p-queue to latest, remove patch (Mikael Finstad / #5391)
- meta: enforce `.ts` extension for relative import types (Antoine du Hamel / #5393)
- @uppy/tus: Fix onShouldRetry type signature (Trent Nadeau / #5387)
- @uppy/dashboard,@uppy/drag-drop,@uppy/file-input: Transform the `accept` prop into a string everywhere (Evgenia Karunus / #5380)
- docs: fix getTemporarySecurityCredentials in aws-s3 (Merlijn Vos / #5363)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants