fix(api): non-empty stack_trace on recent-errors for legacy rows

When occurrence.stack_trace is null/blank, synthesize the same text as
ingest-api (BIT-796) at read time so CRM / Paperclip always get a stable
contract (BIT-1008, ERRPAYLOAD:5d26a50c83c0). Add unit tests and document
in HTTP_CONTRACTS + ERROR_MONITORING_PUBLIC_API.

Paperclip-Agent: 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376
Paperclip-Issue: BIT-1008
Paperclip-Run: 4c4da0dd-38ab-4f32-86d7-f2502c7cceca
Made-with: Cursor
This commit is contained in:
Peter Spark committed 2026-04-05 10:49:24 +00:00
1 parent eaa326e2bb
commit 6971b7669c
5 files changed
+71 -4

No files matched your search

+11 -3
View File
@@ -18,6 +18,7 @@
import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
import type { RowDataPacket } from 'mysql2';
import { authorizeReadQuery } from '../../lib/errorMonitoringAuth.js';
import { synthesizeStackTraceForDisplay } from '../../lib/synthesizeStackTraceForDisplay.js';
const INCIDENT_STATES = ['open', 'investigating', 'resolved', 'ignored'] as const;
const SEVERITIES = ['critical', 'high', 'medium', 'low', 'info'] as const;
@@ -185,12 +186,19 @@ async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply):
const incSev = String(row.incident_severity ?? 'medium').toLowerCase();
const sev = ['critical', 'high', 'medium', 'low'].includes(incSev) ? incSev : 'medium';
const st = String(row.incident_state ?? 'open').toLowerCase();
const message = String(row.message ?? '');
const rawStack =
row.stack_trace != null && String(row.stack_trace).trim() !== ''
? String(row.stack_trace).trim()
: '';
const stack_trace =
rawStack !== '' ? rawStack : synthesizeStackTraceForDisplay(message, ctx);
return {
status: st === 'resolved' ? 'resolved' : st === 'ignored' ? 'ignored' : 'open',
message: String(row.message ?? ''),
error_message: String(row.message ?? ''),
stack_trace: row.stack_trace != null ? String(row.stack_trace) : '',
message,
error_message: message,
stack_trace,
file_path,
line_number,
severity: sev,