From: Chocobozzz Date: Fri, 7 Jul 2017 16:26:12 +0000 (+0200) Subject: Fix error logging X-Git-Tag: v0.0.1-alpha~375 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ad0997adfb9e1e3b1ff54338d7558cf7b18440ea;p=oweals%2Fpeertube.git Fix error logging --- diff --git a/server/controllers/api/pods.ts b/server/controllers/api/pods.ts index 0f85ab51d..55a7df661 100644 --- a/server/controllers/api/pods.ts +++ b/server/controllers/api/pods.ts @@ -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() diff --git a/server/controllers/api/remote/videos.ts b/server/controllers/api/remote/videos.ts index eb033637e..fac85c3a8 100644 --- a/server/controllers/api/remote/videos.ts +++ b/server/controllers/api/remote/videos.ts @@ -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 }) } diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 6e0bb474a..845facd55 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -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) }) } diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index fcbd5465f..3b1b7f58e 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts @@ -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 }) } diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index e4be6f0f9..d8f2068ec 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts @@ -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) }) } diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index ed1f21d66..3532c753e 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -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) }) } diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index 3d119d98b..dfb5a450f 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts @@ -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 }) } diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index f761cfb89..e174dc3e9 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts @@ -17,7 +17,7 @@ function retryTransactionWrapper (functionToRetry: (... args) => Promise, o ) .catch(err => { // Do not throw the error, continue the process - logger.error(options.errorMessage, { error: err }) + logger.error(options.errorMessage, err) }) } diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 0c73e8539..89aef99c4 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -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('') } } diff --git a/server/lib/friends.ts b/server/lib/friends.ts index c24839cb6..3487addbe 100644 --- a/server/lib/friends.ts +++ b/server/lib/friends.ts @@ -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) diff --git a/server/lib/jobs/handlers/video-transcoder.ts b/server/lib/jobs/handlers/video-transcoder.ts index e829ca813..eeb2d57b0 100644 --- a/server/lib/jobs/handlers/video-transcoder.ts +++ b/server/lib/jobs/handlers/video-transcoder.ts @@ -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() } diff --git a/server/lib/jobs/job-scheduler.ts b/server/lib/jobs/job-scheduler.ts index 248dc7978..2ae732b0f 100644 --- a/server/lib/jobs/job-scheduler.ts +++ b/server/lib/jobs/job-scheduler.ts @@ -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) } } diff --git a/server/lib/request/abstract-request-scheduler.ts b/server/lib/request/abstract-request-scheduler.ts index 128fc5b28..0a9ff65d5 100644 --- a/server/lib/request/abstract-request-scheduler.ts +++ b/server/lib/request/abstract-request-scheduler.ts @@ -84,7 +84,7 @@ abstract class AbstractRequestScheduler { } }) .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 { }) .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 })) }) diff --git a/server/lib/request/request-scheduler.ts b/server/lib/request/request-scheduler.ts index 8927d53bb..3945ace20 100644 --- a/server/lib/request/request-scheduler.ts +++ b/server/lib/request/request-scheduler.ts @@ -87,7 +87,7 @@ class RequestScheduler extends AbstractRequestScheduler { 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)) } } diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts index d545b3e58..fe0490436 100644 --- a/server/middlewares/oauth.ts +++ b/server/middlewares/oauth.ts @@ -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) } diff --git a/server/middlewares/validators/pods.ts b/server/middlewares/validators/pods.ts index da7fc2bd6..022fd7f9a 100644 --- a/server/middlewares/validators/pods.ts +++ b/server/middlewares/validators/pods.ts @@ -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) }) }) diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index c06735047..9db4fff77 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -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) }) }) diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index ec452cade..013466487 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts @@ -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) }) } diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts index 8c6883465..a0a13aab7 100644 --- a/server/models/oauth/oauth-token.ts +++ b/server/models/oauth/oauth-token.ts @@ -114,7 +114,7 @@ getByRefreshTokenAndPopulateClient = function (refreshToken: string) { return tokenInfos }).catch(function (err) { - logger.info('getRefreshToken error.', { error: err }) + logger.info('getRefreshToken error.', err) }) } diff --git a/server/models/pod/pod.ts b/server/models/pod/pod.ts index 9209380fc..62d9e3c6c 100644 --- a/server/models/pod/pod.ts +++ b/server/models/pod/pod.ts @@ -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) }) } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 3d71e8d9e..47d3cad1d 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -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)