Fix error logging

This commit is contained in:
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) makeFriends(hosts)
.then(() => logger.info('Made friends!')) .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 // Don't wait the process that could be long
res.type('json').status(204).end() 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) 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 // Don't block the other pod
return res.type('json').status(204).end() 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) 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() return res.type('json').status(204).end()
} }
@ -105,7 +105,7 @@ function remoteVideosEvents (req: express.Request, res: express.Response, next:
return processVideosEventsRetryWrapper(eventData, fromPod) 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() 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)) .then(() => logger.info('Remote video event processed for video %s.', eventData.remoteId))
.catch(err => { .catch(err => {
logger.debug('Cannot process a video event.', { error: err }) logger.debug('Cannot process a video event.', err)
throw err throw err
}) })
} }
@ -207,7 +207,7 @@ function quickAndDirtyUpdateVideo (videoData: any, fromPod: PodInstance) {
}) })
}) })
.then(() => logger.info('Remote video %s quick and dirty updated', videoName)) .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 // Handle retries on fail
@ -287,7 +287,7 @@ function addRemoteVideo (videoToCreateData: any, fromPod: PodInstance) {
}) })
.then(() => logger.info('Remote video %s inserted.', videoToCreateData.name)) .then(() => logger.info('Remote video %s inserted.', videoToCreateData.name))
.catch(err => { .catch(err => {
logger.debug('Cannot insert the remote video.', { error: err }) logger.debug('Cannot insert the remote video.', err)
throw err throw err
}) })
} }
@ -341,7 +341,7 @@ function updateRemoteVideo (videoAttributesToUpdate: any, fromPod: PodInstance)
.then(() => logger.info('Remote video %s updated', videoAttributesToUpdate.name)) .then(() => logger.info('Remote video %s updated', videoAttributesToUpdate.name))
.catch(err => { .catch(err => {
// This is just a debug because we will retry the insert // 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 throw err
}) })
} }
@ -354,7 +354,7 @@ function removeRemoteVideo (videoToRemoveData: any, fromPod: PodInstance) {
return video.destroy() return video.destroy()
}) })
.catch(err => { .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) 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) { function fetchOwnedVideo (id: string) {
@ -383,7 +383,7 @@ function fetchOwnedVideo (id: string) {
return video return video
}) })
.catch(err => { .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 throw err
}) })
} }
@ -396,7 +396,7 @@ function fetchRemoteVideo (podHost: string, remoteId: string) {
return video return video
}) })
.catch(err => { .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 throw err
}) })
} }

View File

@ -126,7 +126,7 @@ function removeUser (req: express.Request, res: express.Response, next: express.
.then(user => user.destroy()) .then(user => user.destroy())
.then(() => res.sendStatus(204)) .then(() => res.sendStatus(204))
.catch(err => { .catch(err => {
logger.error('Errors when removed the user.', { error: err }) logger.error('Errors when removed the user.', err)
return next(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)) .then((videoInstance: VideoInstance) => logger.info('Abuse report for video %s created.', videoInstance.name))
.catch(err => { .catch(err => {
logger.debug('Cannot update the video.', { error: err }) logger.debug('Cannot update the video.', err)
throw err throw err
}) })
} }

View File

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

View File

@ -63,7 +63,7 @@ const storage = multer.diskStorage({
cb(null, filename + '.' + extension) cb(null, filename + '.' + extension)
}) })
.catch(err => { .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 throw err
}) })
} }
@ -304,7 +304,7 @@ function updateVideo (req: express.Request, res: express.Response) {
logger.info('Video with name %s updated.', videoInstance.name) logger.info('Video with name %s updated.', videoInstance.name)
}) })
.catch(err => { .catch(err => {
logger.debug('Cannot update the video.', { error: err }) logger.debug('Cannot update the video.', err)
// Force fields we want to update // Force fields we want to update
// If the transaction is retried, sequelize will think the object has not changed // 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) 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 { } else {
// Just send the event to our friends // Just send the event to our friends
const eventParams = { const eventParams = {
@ -359,7 +359,7 @@ function removeVideo (req: express.Request, res: express.Response, next: express
videoInstance.destroy() videoInstance.destroy()
.then(() => res.type('json').status(204).end()) .then(() => res.type('json').status(204).end())
.catch(err => { .catch(err => {
logger.error('Errors when removed the video.', { error: err }) logger.error('Errors when removed the video.', err)
return next(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)) .then(() => logger.info('User video rate for video %s of user %s updated.', videoInstance.name, userInstance.username))
.catch(err => { .catch(err => {
// This is just a debug because we will retry the insert // 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 throw err
}) })
} }

View File

@ -17,7 +17,7 @@ function retryTransactionWrapper (functionToRetry: (... args) => Promise<any>, o
) )
.catch(err => { .catch(err => {
// Do not throw the error, continue the process // 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 { try {
dataString = JSON.stringify(data) dataString = JSON.stringify(data)
} catch (err) { } catch (err) {
logger.error('Cannot check signature.', { error: err }) logger.error('Cannot check signature.', err)
return false return false
} }
} }
@ -51,7 +51,7 @@ function sign (data: string|Object) {
try { try {
dataString = JSON.stringify(data) dataString = JSON.stringify(data)
} catch (err) { } catch (err) {
logger.error('Cannot sign data.', { error: err }) logger.error('Cannot sign data.', err)
return Promise.resolve('') return Promise.resolve('')
} }
} }

View File

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

View File

@ -51,13 +51,13 @@ class JobScheduler {
// Optimization: we could use "drain" from queue object // Optimization: we could use "drain" from queue object
return setTimeout(next, JOBS_FETCHING_INTERVAL) 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) { createJob (transaction: Sequelize.Transaction, handlerName: string, handlerInputData: object) {
@ -95,7 +95,7 @@ class JobScheduler {
}, },
err => { 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) return this.onJobError(jobHandler, job, err)
} }
) )
@ -123,7 +123,7 @@ class JobScheduler {
} }
private cannotSaveJobError (err: Error) { 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 => { .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 throw err
}) })
@ -124,7 +124,7 @@ abstract class AbstractRequestScheduler <T> {
}) })
.catch(err => { .catch(err => {
badPods.push(requestToMake.toPod.id) 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 })) }, { concurrency: REQUESTS_IN_PARALLEL }).then(() => ({ goodPods, badPods }))
}) })

View File

@ -87,7 +87,7 @@ class RequestScheduler extends AbstractRequestScheduler<RequestsGrouped> {
afterRequestsHook () { afterRequestsHook () {
// Flush requests with no pod // Flush requests with no pod
this.getRequestModel().removeWithEmptyTo() 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) { function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) {
oAuthServer.authenticate()(req, res, function (err) { oAuthServer.authenticate()(req, res, function (err) {
if (err) { if (err) {
logger.error('Cannot authenticate.', { error: err }) logger.error('Cannot authenticate.', err)
return res.sendStatus(500) return res.sendStatus(500)
} }

View File

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

View File

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

View File

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

View File

@ -114,7 +114,7 @@ getByRefreshTokenAndPopulateClient = function (refreshToken: string) {
return tokenInfos return tokenInfos
}).catch(function (err) { }).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) { if (goodPods.length !== 0) {
incrementScores(goodPods, PODS_SCORE.BONUS).catch(err => { 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) incrementScores(badPods, PODS_SCORE.MALUS)
.then(() => removeBadPods()) .then(() => removeBadPods())
.catch(err => { .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 => { .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 => { .catch(err => {
// Autodesctruction... // Autodesctruction...
video.destroy().asCallback(function (err) { 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) return rej(err)