mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Update to OError3
This commit is contained in:
parent
588979bbff
commit
990bacf3c2
7 changed files with 89 additions and 87 deletions
|
@ -17,12 +17,12 @@
|
|||
"author": "Overleaf (https://www.overleaf.com/)",
|
||||
"license": "AGPL-3.0",
|
||||
"dependencies": {
|
||||
"@google-cloud/storage": "^5.1.0",
|
||||
"@overleaf/o-error": "^2.1.0",
|
||||
"aws-sdk": "^2.696.0",
|
||||
"@google-cloud/storage": "^5.1.1",
|
||||
"@overleaf/o-error": "^3.0.0",
|
||||
"aws-sdk": "^2.710.0",
|
||||
"fast-crc32c": "^2.0.0",
|
||||
"glob": "^7.1.6",
|
||||
"logger-sharelatex": "^2.0.0",
|
||||
"logger-sharelatex": "^2.1.1",
|
||||
"node-uuid": "^1.4.8",
|
||||
"range-parser": "^1.2.1",
|
||||
"tiny-async-pool": "^1.1.0"
|
||||
|
|
|
@ -2,80 +2,95 @@ const { NotImplementedError } = require('./Errors')
|
|||
|
||||
module.exports = class AbstractPersistor {
|
||||
async sendFile(location, target, source) {
|
||||
throw new NotImplementedError({
|
||||
message: 'method not implemented in persistor',
|
||||
info: { method: 'sendFile', location, target, source }
|
||||
throw new NotImplementedError('method not implemented in persistor', {
|
||||
method: 'sendFile',
|
||||
location,
|
||||
target,
|
||||
source
|
||||
})
|
||||
}
|
||||
|
||||
async sendStream(location, target, sourceStream, sourceMd5) {
|
||||
throw new NotImplementedError({
|
||||
message: 'method not implemented in persistor',
|
||||
info: { method: 'sendStream', location, target, sourceMd5 }
|
||||
throw new NotImplementedError('method not implemented in persistor', {
|
||||
method: 'sendStream',
|
||||
location,
|
||||
target,
|
||||
sourceMd5
|
||||
})
|
||||
}
|
||||
|
||||
// opts may be {start: Number, end: Number}
|
||||
async getObjectStream(location, name, opts) {
|
||||
throw new NotImplementedError({
|
||||
message: 'method not implemented in persistor',
|
||||
info: { method: 'getObjectStream', location, name, opts }
|
||||
throw new NotImplementedError('method not implemented in persistor', {
|
||||
method: 'getObjectStream',
|
||||
location,
|
||||
name,
|
||||
opts
|
||||
})
|
||||
}
|
||||
|
||||
async getRedirectUrl(location, name) {
|
||||
throw new NotImplementedError({
|
||||
message: 'method not implemented in persistor',
|
||||
info: { method: 'getRedirectUrl', location, name }
|
||||
throw new NotImplementedError('method not implemented in persistor', {
|
||||
method: 'getRedirectUrl',
|
||||
location,
|
||||
name
|
||||
})
|
||||
}
|
||||
|
||||
async getObjectSize(location, name) {
|
||||
throw new NotImplementedError({
|
||||
message: 'method not implemented in persistor',
|
||||
info: { method: 'getObjectSize', location, name }
|
||||
throw new NotImplementedError('method not implemented in persistor', {
|
||||
method: 'getObjectSize',
|
||||
location,
|
||||
name
|
||||
})
|
||||
}
|
||||
|
||||
async getObjectMd5Hash(location, name) {
|
||||
throw new NotImplementedError({
|
||||
message: 'method not implemented in persistor',
|
||||
info: { method: 'getObjectMd5Hash', location, name }
|
||||
throw new NotImplementedError('method not implemented in persistor', {
|
||||
method: 'getObjectMd5Hash',
|
||||
location,
|
||||
name
|
||||
})
|
||||
}
|
||||
|
||||
async copyObject(location, fromName, toName) {
|
||||
throw new NotImplementedError({
|
||||
message: 'method not implemented in persistor',
|
||||
info: { method: 'copyObject', location, fromName, toName }
|
||||
throw new NotImplementedError('method not implemented in persistor', {
|
||||
method: 'copyObject',
|
||||
location,
|
||||
fromName,
|
||||
toName
|
||||
})
|
||||
}
|
||||
|
||||
async deleteObject(location, name) {
|
||||
throw new NotImplementedError({
|
||||
message: 'method not implemented in persistor',
|
||||
info: { method: 'deleteObject', location, name }
|
||||
throw new NotImplementedError('method not implemented in persistor', {
|
||||
method: 'deleteObject',
|
||||
location,
|
||||
name
|
||||
})
|
||||
}
|
||||
|
||||
async deleteDirectory(location, name) {
|
||||
throw new NotImplementedError({
|
||||
message: 'method not implemented in persistor',
|
||||
info: { method: 'deleteDirectory', location, name }
|
||||
throw new NotImplementedError('method not implemented in persistor', {
|
||||
method: 'deleteDirectory',
|
||||
location,
|
||||
name
|
||||
})
|
||||
}
|
||||
|
||||
async checkIfObjectExists(location, name) {
|
||||
throw new NotImplementedError({
|
||||
message: 'method not implemented in persistor',
|
||||
info: { method: 'checkIfObjectExists', location, name }
|
||||
throw new NotImplementedError('method not implemented in persistor', {
|
||||
method: 'checkIfObjectExists',
|
||||
location,
|
||||
name
|
||||
})
|
||||
}
|
||||
|
||||
async directorySize(location, name) {
|
||||
throw new NotImplementedError({
|
||||
message: 'method not implemented in persistor',
|
||||
info: { method: 'directorySize', location, name }
|
||||
throw new NotImplementedError('method not implemented in persistor', {
|
||||
method: 'directorySize',
|
||||
location,
|
||||
name
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,9 +54,11 @@ module.exports = class FSPersistor extends AbstractPersistor {
|
|||
const destMd5 = await this.getObjectMd5Hash(location, target)
|
||||
if (sourceMd5 !== destMd5) {
|
||||
await this._deleteFile(`${location}/${filterName(target)}`)
|
||||
throw new WriteError({
|
||||
message: 'md5 hash mismatch',
|
||||
info: { sourceMd5, destMd5, location, target }
|
||||
throw new WriteError('md5 hash mismatch', {
|
||||
sourceMd5,
|
||||
destMd5,
|
||||
location,
|
||||
target
|
||||
})
|
||||
}
|
||||
} finally {
|
||||
|
@ -108,10 +110,11 @@ module.exports = class FSPersistor extends AbstractPersistor {
|
|||
try {
|
||||
return await FSPersistor._getFileMd5HashForPath(fullPath)
|
||||
} catch (err) {
|
||||
throw new ReadError({
|
||||
message: 'unable to get md5 hash from file',
|
||||
info: { location, filename }
|
||||
}).withCause(err)
|
||||
throw new ReadError(
|
||||
'unable to get md5 hash from file',
|
||||
{ location, filename },
|
||||
err
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,10 +251,7 @@ module.exports = class FSPersistor extends AbstractPersistor {
|
|||
} catch (err) {
|
||||
await this._deleteFile(fsPath)
|
||||
|
||||
throw new WriteError({
|
||||
message: 'problem writing file locally',
|
||||
info: { err, fsPath }
|
||||
}).withCause(err)
|
||||
throw new WriteError('problem writing file locally', { err, fsPath }, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,10 +263,7 @@ module.exports = class FSPersistor extends AbstractPersistor {
|
|||
await fsUnlink(fsPath)
|
||||
} catch (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw new WriteError({
|
||||
message: 'failed to delete file',
|
||||
info: { fsPath }
|
||||
}).withCause(err)
|
||||
throw new WriteError('failed to delete file', { fsPath }, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,15 +179,16 @@ module.exports = class MigrationPersistor extends AbstractPersistor {
|
|||
sourceMd5
|
||||
)
|
||||
} catch (err) {
|
||||
const error = new WriteError({
|
||||
message: 'unable to copy file to destination persistor',
|
||||
info: {
|
||||
const error = new WriteError(
|
||||
'unable to copy file to destination persistor',
|
||||
{
|
||||
sourceBucket,
|
||||
destBucket,
|
||||
sourceKey,
|
||||
destKey
|
||||
}
|
||||
}).withCause(err)
|
||||
},
|
||||
err
|
||||
)
|
||||
if (this.settings.Metrics) {
|
||||
this.settings.Metrics.inc('fallback.copy.failure')
|
||||
}
|
||||
|
@ -195,13 +196,14 @@ module.exports = class MigrationPersistor extends AbstractPersistor {
|
|||
try {
|
||||
await this.primaryPersistor.deleteObject(destBucket, destKey)
|
||||
} catch (err) {
|
||||
error.info.cleanupError = new WriteError({
|
||||
message: 'unable to clean up destination copy artifact',
|
||||
info: {
|
||||
error.info.cleanupError = new WriteError(
|
||||
'unable to clean up destination copy artifact',
|
||||
{
|
||||
destBucket,
|
||||
destKey
|
||||
}
|
||||
}).withCause(err)
|
||||
},
|
||||
err
|
||||
)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ function getPersistor(backend, settings) {
|
|||
Object.assign({}, settings.gcs, { Metrics: settings.Metrics })
|
||||
)
|
||||
default:
|
||||
throw new SettingsError({ message: 'unknown backend', info: { backend } })
|
||||
throw new SettingsError('unknown backend', { backend })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,10 +35,7 @@ module.exports = function create(settings) {
|
|||
'Loading backend'
|
||||
)
|
||||
if (!settings.backend) {
|
||||
throw new SettingsError({
|
||||
message: 'no backend specified - config incomplete',
|
||||
info: {}
|
||||
})
|
||||
throw new SettingsError('no backend specified - config incomplete')
|
||||
}
|
||||
|
||||
let persistor = getPersistor(settings.backend, settings)
|
||||
|
|
|
@ -80,14 +80,11 @@ async function verifyMd5(persistor, bucket, key, sourceMd5, destMd5 = null) {
|
|||
Logger.warn(err, 'error deleting file for invalid upload')
|
||||
}
|
||||
|
||||
throw new WriteError({
|
||||
message: 'source and destination hashes do not match',
|
||||
info: {
|
||||
sourceMd5,
|
||||
destMd5,
|
||||
bucket,
|
||||
key
|
||||
}
|
||||
throw new WriteError('source and destination hashes do not match', {
|
||||
sourceMd5,
|
||||
destMd5,
|
||||
bucket,
|
||||
key
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -164,15 +161,9 @@ function wrapError(error, message, params, ErrorType) {
|
|||
) ||
|
||||
(error.response && error.response.statusCode === 404)
|
||||
) {
|
||||
return new NotFoundError({
|
||||
message: 'no such file',
|
||||
info: params
|
||||
}).withCause(error)
|
||||
return new NotFoundError('no such file', params, error)
|
||||
} else {
|
||||
return new ErrorType({
|
||||
message: message,
|
||||
info: params
|
||||
}).withCause(error)
|
||||
return new ErrorType(message, params, error)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -306,10 +306,10 @@ module.exports = class S3Persistor extends AbstractPersistor {
|
|||
return new S3(this._buildClientOptions(null, clientOptions))
|
||||
}
|
||||
|
||||
throw new SettingsError({
|
||||
message: 'no bucket-specific or default credentials provided',
|
||||
info: { bucket }
|
||||
})
|
||||
throw new SettingsError(
|
||||
'no bucket-specific or default credentials provided',
|
||||
{ bucket }
|
||||
)
|
||||
}
|
||||
|
||||
_buildClientOptions(bucketCredentials, clientOptions) {
|
||||
|
|
Loading…
Reference in a new issue