[misc] OError.tag all the errors in async contexts

See the docs of OError.tag:
https://github.com/overleaf/o-error#long-stack-traces-with-oerrortag
(currently at 221dd902e7bfa0ee92de1ea5a3cbf3152c3ceeb4)

I am tagging all errors at each async hop. Most of the controller code
 will only ever see already tagged errors -- or new errors created in
 our app code. They should have enough info that we do not need to tag
 them again.
This commit is contained in:
Jakob Ackermann
2020-08-24 10:12:06 +01:00
parent c7b9dadd16
commit 537e97be73
8 changed files with 63 additions and 58 deletions
@@ -5,6 +5,7 @@ const async = require('async')
const Settings = require('settings-sharelatex')
const logger = require('logger-sharelatex')
const redis = require('redis-sharelatex')
const OError = require('@overleaf/o-error')
const rclient = redis.createClient(Settings.redis.realtime)
const Keys = Settings.redis.realtime.key_schema
@@ -67,10 +68,7 @@ module.exports = {
multi.exec(function (err) {
if (err) {
logger.err(
{ err, project_id, client_id },
'problem marking user as connected'
)
OError.tag(err, 'problem marking user as connected')
}
callback(err)
})
@@ -104,7 +102,12 @@ module.exports = {
multi.srem(Keys.clientsInProject({ project_id }), client_id)
multi.expire(Keys.clientsInProject({ project_id }), FOUR_DAYS_IN_S)
multi.del(Keys.connectedUser({ project_id, client_id }))
multi.exec(callback)
multi.exec(function (err) {
if (err) {
OError.tag(err, 'problem marking user as disconnected')
}
callback(err)
})
},
_getConnectedUser(project_id, client_id, callback) {
@@ -112,6 +115,12 @@ module.exports = {
err,
result
) {
if (err) {
OError.tag(err, 'problem fetching connected user details', {
other_client_id: client_id
})
return callback(err)
}
if (!(result && result.user_id)) {
result = {
connected: false,
@@ -126,15 +135,10 @@ module.exports = {
try {
result.cursorData = JSON.parse(result.cursorData)
} catch (e) {
logger.error(
{
err: e,
project_id,
client_id,
cursorData: result.cursorData
},
'error parsing cursorData JSON'
)
OError.tag(e, 'error parsing cursorData JSON', {
other_client_id: client_id,
cursorData: result.cursorData
})
return callback(e)
}
}
@@ -150,6 +154,7 @@ module.exports = {
results
) {
if (err) {
OError.tag(err, 'problem getting clients in project')
return callback(err)
}
const jobs = results.map((client_id) => (cb) =>
@@ -157,6 +162,7 @@ module.exports = {
)
async.series(jobs, function (err, users) {
if (err) {
OError.tag(err, 'problem getting connected users')
return callback(err)
}
users = users.filter(