diff --git a/lib/middleware/onerror.js b/lib/middleware/onerror.js index ea71b528e2..d8f6d43bbf 100644 --- a/lib/middleware/onerror.js +++ b/lib/middleware/onerror.js @@ -6,6 +6,7 @@ const path = require('path'); const { RequestInProgressError } = require('@/errors'); let Sentry; +let gitHash; if (config.sentry.dsn) { Sentry = Sentry || require('@sentry/node'); @@ -19,6 +20,12 @@ if (config.sentry.dsn) { logger.info('Sentry inited.'); } +try { + gitHash = require('git-rev-sync').short(); +} catch (e) { + gitHash = (process.env.HEROKU_SLUG_COMMIT && process.env.HEROKU_SLUG_COMMIT.slice(0, 7)) || (process.env.VERCEL_GITHUB_COMMIT_SHA && process.env.VERCEL_GITHUB_COMMIT_SHA.slice(0, 7)) || 'unknown'; +} + module.exports = async (ctx, next) => { try { const time = +new Date(); @@ -68,6 +75,7 @@ module.exports = async (ctx, next) => { message, errorPath: ctx.path, nodeVersion: process.version, + gitHash, }); } diff --git a/lib/views/error.art b/lib/views/error.art index 561030cc02..431c9063c0 100644 --- a/lib/views/error.art +++ b/lib/views/error.art @@ -43,6 +43,7 @@ Helpful Information to provide when opening issue: Path: {{@ errorPath }} Node version: {{@ nodeVersion}} +Git Hash: {{@ gitHash}}
 如果您认为 RSSHub 导致了该错误,请在Github按照模版,复制本页面信息进行汇报