Fix error logging

pull/76/head
Chocobozzz 2017-07-07 18:26:12 +02:00
parent 709756b8e1
commit ad0997adfb
21 changed files with 49 additions and 49 deletions

View File

@ -81,7 +81,7 @@ function makeFriendsController (req: express.Request, res: express.Response, nex
makeFriends(hosts)
.then(() => logger.info('Made friends!'))
.catch(err => logger.error('Could not make friends.', { error: err }))
.catch(err => logger.error('Could not make friends.', err))
// Don't wait the process that could be long
res.type('json').status(204).end()

View File

@ -76,7 +76,7 @@ function remoteVideos (req: express.Request, res: express.Response, next: expres
return fun.call(this, data, fromPod)
})
.catch(err => logger.error('Error managing remote videos.', { error: err }))
.catch(err => logger.error('Error managing remote videos.', err))
// Don't block the other pod
return res.type('json').status(204).end()
@ -91,7 +91,7 @@ function remoteVideosQadu (req: express.Request, res: express.Response, next: ex
return quickAndDirtyUpdateVideoRetryWrapper(videoData, fromPod)
})
.catch(err => logger.error('Error managing remote videos.', { error: err }))
.catch(err => logger.error('Error managing remote videos.', err))
return res.type('json').status(204).end()
}
@ -105,7 +105,7 @@ function remoteVideosEvents (req: express.Request, res: express.Response, next:
return processVideosEventsRetryWrapper(eventData, fromPod)
})
.catch(err => logger.error('Error managing remote videos.', { error: err }))
.catch(err => logger.error('Error managing remote videos.', err))
return res.type('json').status(204).end()
}
@ -167,7 +167,7 @@ function processVideosEvents (eventData: any, fromPod: PodInstance) {
})
.then(() => logger.info('Remote video event processed for video %s.', eventData.remoteId))
.catch(err => {
logger.debug('Cannot process a video event.', { error: err })
logger.debug('Cannot process a video event.', err)
throw err
})
}
@ -207,7 +207,7 @@ function quickAndDirtyUpdateVideo (videoData: any, fromPod: PodInstance) {
})
})
.then(() => logger.info('Remote video %s quick and dirty updated', videoName))
.catch(err => logger.debug('Cannot quick and dirty update the remote video.', { error: err }))
.catch(err => logger.debug('Cannot quick and dirty update the remote video.', err))
}
// Handle retries on fail
@ -287,7 +287,7 @@ function addRemoteVideo (videoToCreateData: any, fromPod: PodInstance) {
})
.then(() => logger.info('Remote video %s inserted.', videoToCreateData.name))
.catch(err => {
logger.debug('Cannot insert the remote video.', { error: err })
logger.debug('Cannot insert the remote video.', err)
throw err
})
}
@ -341,7 +341,7 @@ function updateRemoteVideo (videoAttributesToUpdate: any, fromPod: PodInstance)
.then(() => logger.info('Remote video %s updated', videoAttributesToUpdate.name))
.catch(err => {
// This is just a debug because we will retry the insert
logger.debug('Cannot update the remote video.', { error: err })
logger.debug('Cannot update the remote video.', err)
throw err
})
}
@ -354,7 +354,7 @@ function removeRemoteVideo (videoToRemoveData: any, fromPod: PodInstance) {
return video.destroy()
})
.catch(err => {
logger.debug('Could not fetch remote video.', { host: fromPod.host, remoteId: videoToRemoveData.remoteId, error: err })
logger.debug('Could not fetch remote video.', { host: fromPod.host, remoteId: videoToRemoveData.remoteId, error: err.stack })
})
}
@ -372,7 +372,7 @@ function reportAbuseRemoteVideo (reportData: any, fromPod: PodInstance) {
return db.VideoAbuse.create(videoAbuseData)
})
.catch(err => logger.error('Cannot create remote abuse video.', { error: err }))
.catch(err => logger.error('Cannot create remote abuse video.', err))
}
function fetchOwnedVideo (id: string) {
@ -383,7 +383,7 @@ function fetchOwnedVideo (id: string) {
return video
})
.catch(err => {
logger.error('Cannot load owned video from id.', { error: err, id })
logger.error('Cannot load owned video from id.', { error: err.stack, id })
throw err
})
}
@ -396,7 +396,7 @@ function fetchRemoteVideo (podHost: string, remoteId: string) {
return video
})
.catch(err => {
logger.error('Cannot load video from host and remote id.', { error: err, podHost, remoteId })
logger.error('Cannot load video from host and remote id.', { error: err.stack, podHost, remoteId })
throw err
})
}

View File

@ -126,7 +126,7 @@ function removeUser (req: express.Request, res: express.Response, next: express.
.then(user => user.destroy())
.then(() => res.sendStatus(204))
.catch(err => {
logger.error('Errors when removed the user.', { error: err })
logger.error('Errors when removed the user.', err)
return next(err)
})
}

View File

@ -90,7 +90,7 @@ function reportVideoAbuse (req: express.Request, res: express.Response) {
})
.then((videoInstance: VideoInstance) => logger.info('Abuse report for video %s created.', videoInstance.name))
.catch(err => {
logger.debug('Cannot update the video.', { error: err })
logger.debug('Cannot update the video.', err)
throw err
})
}

View File

@ -35,7 +35,7 @@ function addVideoToBlacklist (req: express.Request, res: express.Response, next:
db.BlacklistedVideo.create(toCreate)
.then(() => res.type('json').status(204).end())
.catch(err => {
logger.error('Errors when blacklisting video ', { error: err })
logger.error('Errors when blacklisting video ', err)
return next(err)
})
}

View File

@ -63,7 +63,7 @@ const storage = multer.diskStorage({
cb(null, filename + '.' + extension)
})
.catch(err => {
logger.error('Cannot generate random string for file name.', { error: err })
logger.error('Cannot generate random string for file name.', err)
throw err
})
}
@ -304,7 +304,7 @@ function updateVideo (req: express.Request, res: express.Response) {
logger.info('Video with name %s updated.', videoInstance.name)
})
.catch(err => {
logger.debug('Cannot update the video.', { error: err })
logger.debug('Cannot update the video.', err)
// Force fields we want to update
// If the transaction is retried, sequelize will think the object has not changed
@ -333,7 +333,7 @@ function getVideo (req: express.Request, res: express.Response, next: express.Ne
}
return quickAndDirtyUpdateVideoToFriends(qaduParams)
})
.catch(err => logger.error('Cannot add view to video %d.', videoInstance.id, { error: err }))
.catch(err => logger.error('Cannot add view to video %d.', videoInstance.id, err))
} else {
// Just send the event to our friends
const eventParams = {
@ -359,7 +359,7 @@ function removeVideo (req: express.Request, res: express.Response, next: express
videoInstance.destroy()
.then(() => res.type('json').status(204).end())
.catch(err => {
logger.error('Errors when removed the video.', { error: err })
logger.error('Errors when removed the video.', err)
return next(err)
})
}

View File

@ -143,7 +143,7 @@ function rateVideo (req: express.Request, res: express.Response) {
.then(() => logger.info('User video rate for video %s of user %s updated.', videoInstance.name, userInstance.username))
.catch(err => {
// This is just a debug because we will retry the insert
logger.debug('Cannot add the user video rate.', { error: err })
logger.debug('Cannot add the user video rate.', err)
throw err
})
}

View File

@ -17,7 +17,7 @@ function retryTransactionWrapper (functionToRetry: (... args) => Promise<any>, o
)
.catch(err => {
// Do not throw the error, continue the process
logger.error(options.errorMessage, { error: err })
logger.error(options.errorMessage, err)
})
}

View File

@ -30,7 +30,7 @@ function checkSignature (publicKey: string, data: string, hexSignature: string)
try {
dataString = JSON.stringify(data)
} catch (err) {
logger.error('Cannot check signature.', { error: err })
logger.error('Cannot check signature.', err)
return false
}
}
@ -51,7 +51,7 @@ function sign (data: string|Object) {
try {
dataString = JSON.stringify(data)
} catch (err) {
logger.error('Cannot sign data.', { error: err })
logger.error('Cannot sign data.', err)
return Promise.resolve('')
}
}

View File

@ -180,7 +180,7 @@ function quitFriends () {
}, { concurrency: REQUESTS_IN_PARALLEL })
.then(() => pods)
.catch(err => {
logger.error('Some errors while quitting friends.', { err: err })
logger.error('Some errors while quitting friends.', err)
// Don't stop the process
})
})
@ -215,7 +215,7 @@ function sendOwnedVideosToPod (podId: number) {
return createRequest(options)
})
.catch(err => {
logger.error('Cannot convert video to remote.', { error: err })
logger.error('Cannot convert video to remote.', err)
// Don't break the process
return undefined
})
@ -344,7 +344,7 @@ function makeRequestsToWinningPods (cert: string, podsList: PodInstance[]) {
sendOwnedVideosToPod(podCreated.id)
})
.catch(err => {
logger.error('Cannot add friend %s pod.', pod.host, { error: err })
logger.error('Cannot add friend %s pod.', pod.host, err)
})
} else {
logger.error('Status not 200 for %s pod.', pod.host)

View File

@ -10,7 +10,7 @@ function process (data: { id: string }) {
}
function onError (err: Error, jobId: number) {
logger.error('Error when transcoding video file in job %d.', jobId, { error: err })
logger.error('Error when transcoding video file in job %d.', jobId, err)
return Promise.resolve()
}

View File

@ -51,13 +51,13 @@ class JobScheduler {
// Optimization: we could use "drain" from queue object
return setTimeout(next, JOBS_FETCHING_INTERVAL)
})
.catch(err => logger.error('Cannot list pending jobs.', { error: err }))
.catch(err => logger.error('Cannot list pending jobs.', err))
},
err => logger.error('Error in job scheduler queue.', { error: err })
err => logger.error('Error in job scheduler queue.', err)
)
})
.catch(err => logger.error('Cannot list pending jobs.', { error: err }))
.catch(err => logger.error('Cannot list pending jobs.', err))
}
createJob (transaction: Sequelize.Transaction, handlerName: string, handlerInputData: object) {
@ -95,7 +95,7 @@ class JobScheduler {
},
err => {
logger.error('Error in job handler %s.', job.handlerName, { error: err })
logger.error('Error in job handler %s.', job.handlerName, err)
return this.onJobError(jobHandler, job, err)
}
)
@ -123,7 +123,7 @@ class JobScheduler {
}
private cannotSaveJobError (err: Error) {
logger.error('Cannot save new job state.', { error: err })
logger.error('Cannot save new job state.', err)
}
}

View File

@ -84,7 +84,7 @@ abstract class AbstractRequestScheduler <T> {
}
})
.catch(err => {
logger.error('Error sending secure request to %s pod.', toPod.host, { error: err })
logger.error('Error sending secure request to %s pod.', toPod.host, err)
throw err
})
@ -124,7 +124,7 @@ abstract class AbstractRequestScheduler <T> {
})
.catch(err => {
badPods.push(requestToMake.toPod.id)
logger.info('Cannot make request to %s.', toPod.host, { error: err })
logger.info('Cannot make request to %s.', toPod.host, err)
})
}, { concurrency: REQUESTS_IN_PARALLEL }).then(() => ({ goodPods, badPods }))
})

View File

@ -87,7 +87,7 @@ class RequestScheduler extends AbstractRequestScheduler<RequestsGrouped> {
afterRequestsHook () {
// Flush requests with no pod
this.getRequestModel().removeWithEmptyTo()
.catch(err => logger.error('Error when removing requests with no pods.', { error: err }))
.catch(err => logger.error('Error when removing requests with no pods.', err))
}
}

View File

@ -14,7 +14,7 @@ const oAuthServer = new OAuthServer({
function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) {
oAuthServer.authenticate()(req, res, function (err) {
if (err) {
logger.error('Cannot authenticate.', { error: err })
logger.error('Cannot authenticate.', err)
return res.sendStatus(500)
}

View File

@ -29,7 +29,7 @@ function makeFriendsValidator (req: express.Request, res: express.Response, next
return next()
})
.catch(err => {
logger.error('Cannot know if we have friends.', { error: err })
logger.error('Cannot know if we have friends.', err)
res.sendStatus(500)
})
})
@ -52,7 +52,7 @@ function podsAddValidator (req: express.Request, res: express.Response, next: ex
return next()
})
.catch(err => {
logger.error('Cannot load pod by host.', { error: err })
logger.error('Cannot load pod by host.', err)
res.sendStatus(500)
})
})

View File

@ -20,7 +20,7 @@ function usersAddValidator (req: express.Request, res: express.Response, next: e
next()
})
.catch(err => {
logger.error('Error in usersAdd request validator.', { error: err })
logger.error('Error in usersAdd request validator.', err)
return res.sendStatus(500)
})
})
@ -41,7 +41,7 @@ function usersRemoveValidator (req: express.Request, res: express.Response, next
next()
})
.catch(err => {
logger.error('Error in usersRemove request validator.', { error: err })
logger.error('Error in usersRemove request validator.', err)
return res.sendStatus(500)
})
})
@ -71,7 +71,7 @@ function usersVideoRatingValidator (req: express.Request, res: express.Response,
next()
})
.catch(err => {
logger.error('Error in user request validator.', { error: err })
logger.error('Error in user request validator.', err)
return res.sendStatus(500)
})
})

View File

@ -33,7 +33,7 @@ function videosAddValidator (req: express.Request, res: express.Response, next:
next()
})
.catch(err => {
logger.error('Error in getting duration from file.', { error: err })
logger.error('Error in getting duration from file.', err)
res.status(400).send('Cannot retrieve metadata of the file.')
})
})
@ -164,7 +164,7 @@ function checkVideoExists (id: string, res: express.Response, callback: () => vo
callback()
})
.catch(err => {
logger.error('Error in video request validator.', { error: err })
logger.error('Error in video request validator.', err)
return res.sendStatus(500)
})
}
@ -190,7 +190,7 @@ function checkUserCanDeleteVideo (userId: number, res: express.Response, callbac
callback()
})
.catch(err => {
logger.error('Error in video request validator.', { error: err })
logger.error('Error in video request validator.', err)
return res.sendStatus(500)
})
}

View File

@ -114,7 +114,7 @@ getByRefreshTokenAndPopulateClient = function (refreshToken: string) {
return tokenInfos
}).catch(function (err) {
logger.info('getRefreshToken error.', { error: err })
logger.info('getRefreshToken error.', err)
})
}

View File

@ -216,7 +216,7 @@ updatePodsScore = function (goodPods: number[], badPods: number[]) {
if (goodPods.length !== 0) {
incrementScores(goodPods, PODS_SCORE.BONUS).catch(err => {
logger.error('Cannot increment scores of good pods.', { error: err })
logger.error('Cannot increment scores of good pods.', err)
})
}
@ -224,7 +224,7 @@ updatePodsScore = function (goodPods: number[], badPods: number[]) {
incrementScores(badPods, PODS_SCORE.MALUS)
.then(() => removeBadPods())
.catch(err => {
if (err) logger.error('Cannot decrement scores of bad pods.', { error: err })
if (err) logger.error('Cannot decrement scores of bad pods.', err)
})
}
}
@ -246,6 +246,6 @@ function removeBadPods () {
}
})
.catch(err => {
logger.error('Cannot remove bad pods.', { error: err })
logger.error('Cannot remove bad pods.', err)
})
}

View File

@ -553,7 +553,7 @@ transcodeVideofile = function (this: VideoInstance) {
.catch(err => {
// Autodesctruction...
video.destroy().asCallback(function (err) {
if (err) logger.error('Cannot destruct video after transcoding failure.', { error: err })
if (err) logger.error('Cannot destruct video after transcoding failure.', err)
})
return rej(err)