From eda43ff7d9238dfb5b85841aab6817a144bb49c2 Mon Sep 17 00:00:00 2001 From: LightZirconite Date: Sat, 6 Dec 2025 13:38:02 +0100 Subject: [PATCH] feat: add request ID and stack snippet to error reports; update scheduling documentation --- api/report-error.js | 14 +++++++++++++- docs/scheduling.md | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/report-error.js b/api/report-error.js index 1606eac..72226c2 100644 --- a/api/report-error.js +++ b/api/report-error.js @@ -1,6 +1,9 @@ +const { randomUUID } = require('crypto') + const MAX_BODY_SIZE = 10000 const MAX_TEXT = 900 const MAX_FIELD = 120 +const MAX_STACK_LINES = 8 const AUTH_HEADER = 'x-error-report-token' function isPlainObject(value) { @@ -96,6 +99,10 @@ module.exports = async function handler(req, res) { const errorType = trimAndLimit(body.type || 'unspecified', 80) const environment = trimAndLimit((body.environment && (body.environment.name || body.environment)) || process.env.VERCEL_ENV || process.env.NODE_ENV || 'unspecified', 80) const metadata = formatMetadata(body.metadata) + const stackSnippet = Array.isArray(body.stack) + ? body.stack.slice(0, MAX_STACK_LINES).join('\n') + : trimAndLimit(typeof body.stack === 'string' ? body.stack.split('\n').slice(0, MAX_STACK_LINES).join('\n') : '', MAX_TEXT) + const requestId = randomUUID() const embed = { title: 'Error Report', @@ -104,7 +111,8 @@ module.exports = async function handler(req, res) { fields: [ { name: 'Error', value: errorText, inline: false }, { name: 'Type', value: errorType, inline: true }, - { name: 'Environment', value: environment, inline: true } + { name: 'Environment', value: environment, inline: true }, + { name: 'Request ID', value: requestId, inline: true } ], footer: { text: 'Microsoft Rewards Bot' }, timestamp: new Date().toISOString() @@ -114,6 +122,10 @@ module.exports = async function handler(req, res) { embed.fields.push({ name: 'Metadata', value: metadata, inline: false }) } + if (stackSnippet) { + embed.fields.push({ name: 'Stack (truncated)', value: stackSnippet }) + } + const payload = { embeds: [embed] } try { diff --git a/docs/scheduling.md b/docs/scheduling.md index 7b5b436..813cbab 100644 --- a/docs/scheduling.md +++ b/docs/scheduling.md @@ -8,7 +8,7 @@ Runs the bot automatically at set times. - Choose a time using the cron or Task Scheduler fields already in the config. - Leave the machine or container running so the schedule can trigger. - Check the console after start: it prints the next run time. If you close the window or stop the container, the scheduler stops. -- Serverless hosts (e.g., Vercel) will not keep the scheduler alive; run on a machine or container that stays on. +- Serverless hosts (e.g., Vercel) will not keep the scheduler alive; run on a machine or container that stays on. Use Vercel only for the API endpoints (like error reporting), not for scheduled runs. ## Example ```jsonc