瀏覽代碼

Attachment migration, add error logs

Martin Filser 3 年之前
父節點
當前提交
47ca6829eb
共有 2 個文件被更改,包括 21 次插入21 次删除
  1. 1 1
      models/lib/fsHooks/createOnAfterUpload.js
  2. 20 20
      server/migrations.js

+ 1 - 1
models/lib/fsHooks/createOnAfterUpload.js

@@ -26,7 +26,7 @@ export const createOnAfterUpload = bucket =>
         // and we unlink the file from the fs on any error
         // that occurred during the upload to prevent zombie files
         .on('error', err => {
-          // console.error(err);
+          console.error("[createOnAfterUpload error]", err);
           self.unlink(this.collection.findOne(file._id), versionName); // Unlink files from FS
         })
 

+ 20 - 20
server/migrations.js

@@ -1146,8 +1146,12 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
     const readStream = fileObj.createReadStream('attachments');
     const writeStream = fs.createWriteStream(filePath);
 
-    writeStream.on('error', function(err) {
-      console.log('Writing error: ', err, filePath);
+    writeStream.on('error', error => {
+      console.error('[writeStream error]: ', error, filePath);
+    });
+
+    readStream.on('error', error => {
+      console.error('[readStream error]: ', error, filePath);
     });
 
     // Once we have a file, then upload it to our new data storage
@@ -1171,11 +1175,11 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
           size: fileSize,
           fileId,
         },
-        (err, fileRef) => {
-          if (err) {
-            console.log(err);
+        (error, fileRef) => {
+          if (error) {
+            console.error('[Attachments#addFile error]: ', error);
           } else {
-            console.log('File Inserted: ', fileRef._id);
+            console.log('File Inserted: ', fileRef);
             // Set the userId again
             Attachments.update({ _id: fileRef._id }, { $set: { userId } });
             fileObj.remove();
@@ -1185,10 +1189,6 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
       ); // proceedAfterUpload
     });
 
-    readStream.on('error', error => {
-      console.log('Error: ', filePath, error);
-    });
-
     readStream.pipe(writeStream);
   });
 });
@@ -1213,8 +1213,12 @@ Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
     const readStream = fileObj.createReadStream('avatars');
     const writeStream = fs.createWriteStream(filePath);
 
-    writeStream.on('error', function(err) {
-      console.log('Writing error: ', err, filePath);
+    writeStream.on('error', error => {
+      console.error('[writeStream error]: ', error, filePath);
+    });
+
+    readStream.on('error', error => {
+      console.error('[readStream error]: ', error, filePath);
     });
 
     // Once we have a file, then upload it to our new data storage
@@ -1237,11 +1241,11 @@ Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
           size: fileSize,
           fileId,
         },
-        (err, fileRef) => {
-          if (err) {
-            console.log(err);
+        (error, fileRef) => {
+          if (error) {
+            console.error('[Avatars#addFile error]: ', error);
           } else {
-            console.log('File Inserted: ', newFileName, fileRef._id);
+            console.log('File Inserted: ', newFileName, fileRef);
             // Set the userId again
             Avatars.update({ _id: fileRef._id }, { $set: { userId } });
             Users.find().forEach(user => {
@@ -1267,10 +1271,6 @@ Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
       );
     });
 
-    readStream.on('error', error => {
-      console.log('Error: ', filePath, error);
-    });
-
     readStream.pipe(writeStream);
   });
 });