Просмотр исходного кода

Remove unnecessary try/catch around 'createReadStream'

Simon Detheridge 6 лет назад
Родитель
Сommit
30114cd79b

+ 1 - 12
services/filestore/app/js/GcsPersistor.js

@@ -53,18 +53,7 @@ const GcsPersistor = {
 module.exports = GcsPersistor
 
 async function sendFile(bucketName, key, fsPath) {
-  let readStream
-  try {
-    readStream = fs.createReadStream(fsPath)
-  } catch (err) {
-    throw PersistorHelper.wrapError(
-      err,
-      'error reading file from disk',
-      { bucketName, key, fsPath },
-      ReadError
-    )
-  }
-  return sendStream(bucketName, key, readStream)
+  return sendStream(bucketName, key, fs.createReadStream(fsPath))
 }
 
 async function sendStream(bucketName, key, readStream, sourceMd5) {

+ 1 - 12
services/filestore/app/js/S3Persistor.js

@@ -46,18 +46,7 @@ const S3Persistor = {
 module.exports = S3Persistor
 
 async function sendFile(bucketName, key, fsPath) {
-  let readStream
-  try {
-    readStream = fs.createReadStream(fsPath)
-  } catch (err) {
-    throw PersistorHelper.wrapError(
-      err,
-      'error reading file from disk',
-      { bucketName, key, fsPath },
-      ReadError
-    )
-  }
-  return sendStream(bucketName, key, readStream)
+  return sendStream(bucketName, key, fs.createReadStream(fsPath))
 }
 
 async function sendStream(bucketName, key, readStream, sourceMd5) {

+ 0 - 42
services/filestore/test/unit/js/GcsPersistorTests.js

@@ -440,48 +440,6 @@ describe('GcsPersistorTests', function() {
         )
       })
     })
-
-    describe('when the file does not exist', function() {
-      let error
-
-      beforeEach(async function() {
-        Fs.createReadStream = sinon.stub().throws(FileNotFoundError)
-        try {
-          await GcsPersistor.promises.sendFile(bucket, key, filename)
-        } catch (err) {
-          error = err
-        }
-      })
-
-      it('returns a NotFoundError', function() {
-        expect(error).to.be.an.instanceOf(Errors.NotFoundError)
-      })
-
-      it('wraps the error', function() {
-        expect(error.cause).to.equal(FileNotFoundError)
-      })
-    })
-
-    describe('when reading the file throws an error', function() {
-      let error
-
-      beforeEach(async function() {
-        Fs.createReadStream = sinon.stub().throws(genericError)
-        try {
-          await GcsPersistor.promises.sendFile(bucket, key, filename)
-        } catch (err) {
-          error = err
-        }
-      })
-
-      it('returns a ReadError', function() {
-        expect(error).to.be.an.instanceOf(Errors.ReadError)
-      })
-
-      it('wraps the error', function() {
-        expect(error.cause).to.equal(genericError)
-      })
-    })
   })
 
   describe('copyFile', function() {

+ 0 - 42
services/filestore/test/unit/js/S3PersistorTests.js

@@ -583,48 +583,6 @@ describe('S3PersistorTests', function() {
         })
       })
     })
-
-    describe('when the file does not exist', function() {
-      let error
-
-      beforeEach(async function() {
-        Fs.createReadStream = sinon.stub().throws(FileNotFoundError)
-        try {
-          await S3Persistor.promises.sendFile(bucket, key, filename)
-        } catch (err) {
-          error = err
-        }
-      })
-
-      it('returns a NotFoundError', function() {
-        expect(error).to.be.an.instanceOf(Errors.NotFoundError)
-      })
-
-      it('wraps the error', function() {
-        expect(error.cause).to.equal(FileNotFoundError)
-      })
-    })
-
-    describe('when reading the file throws an error', function() {
-      let error
-
-      beforeEach(async function() {
-        Fs.createReadStream = sinon.stub().throws(genericError)
-        try {
-          await S3Persistor.promises.sendFile(bucket, key, filename)
-        } catch (err) {
-          error = err
-        }
-      })
-
-      it('returns a ReadError', function() {
-        expect(error).to.be.an.instanceOf(Errors.ReadError)
-      })
-
-      it('wraps the error', function() {
-        expect(error.cause).to.equal(genericError)
-      })
-    })
   })
 
   describe('copyFile', function() {