mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-23 06:43:45 +00:00
Remove unnecessary try/catch around 'createReadStream'
This commit is contained in:
parent
a7198764cb
commit
30114cd79b
4 changed files with 2 additions and 108 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue