Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: summarize route-error details into one log line instead of a JSON blob (#5719)
[._.]/ Adam Eivy3ab8636f1b6c
diff --git a/server/lib/errorHandler.js b/server/lib/errorHandler.jsindex e242129bf6..cd44287136 100644--- a/server/lib/errorHandler.js+++ b/server/lib/errorHandler.js@@ -116,6 +116,50 @@ export function createServiceErrorMapper(statusMap, buildContext) {};}+// Log-line budget for `error.context.details`. Five entries is enough to name+// the offending fields on a typical 400; the char cap keeps a `pg_dump` stderr+// blob (dbAdmin.js puts raw stderr in this field) from swallowing the log.+const LOG_DETAIL_MAX_ENTRIES = 5;+const LOG_DETAIL_MAX_CHARS = 300;++const clampLogText = (value) => {+ const flat = String(value).replace(/\s+/g, ' ').trim();+ return flat.length > LOG_DETAIL_MAX_CHARS ? `${flat.slice(0, LOG_DETAIL_MAX_CHARS)}…` : flat;+};++const describeDetailEntry = (entry) => {+ if (!entry || typeof entry !== 'object') return String(entry);+ const { path, message } = entry;+ if (path && message) return `${path}: ${message}`;+ return String(message || path || '?');+};++/**+ * Render `error.context.details` as ONE readable log line.+ *+ * `validateRequest` sets `details` to the full mapped Zod issue array and+ * `dbAdmin` sets it to raw command stderr, so serializing it as JSON emitted a+ * multi-KB escaped blob per sub-500 — against the single-line logging+ * convention and unreadable in PM2 logs. The field/message pairs are the useful+ * part of a 400, so summarize rather than drop: the first few entries, then a+ * `(+N more)` count. The `(+N more)` suffix is appended AFTER the char clamp so+ * a long first entry can't hide how much was elided.+ *+ * Logging only — `buildErrorEnvelope`/`sanitizeContext` still carry the full+ * structured `details` in the HTTP response body.+ */+const summarizeDetails = (details) => {+ if (Array.isArray(details)) {+ const shown = clampLogText(details.slice(0, LOG_DETAIL_MAX_ENTRIES).map(describeDetailEntry).join('; '));+ const elided = details.length - LOG_DETAIL_MAX_ENTRIES;+ return elided > 0 ? `${shown} (+${elided} more)` : shown;+ }+ if (details && typeof details === 'object') {+ return clampLogText(Object.entries(details).map(([k, v]) => `${k}=${v}`).join('; '));+ }+ return clampLogText(details);+};+export function asyncHandler(fn) {return (req, res, next) => {Promise.resolve(fn(req, res, next)).catch((err) => {@@ -143,7 +187,7 @@ export function asyncHandler(fn) {console.error(logMsg, error.stack ? error.stack : '');} else {const details = error.context?.details;- console.error(details ? `${logMsg}: ${JSON.stringify(details)}` : logMsg);+ console.error(details ? `${logMsg}: ${summarizeDetails(details)}` : logMsg);}return sendErrorResponse(res, error, { io });diff --git a/server/lib/errorHandler.test.js b/server/lib/errorHandler.test.jsindex 87b91ded77..2974592e21 100644--- a/server/lib/errorHandler.test.js+++ b/server/lib/errorHandler.test.js@@ -469,6 +469,72 @@ describe('errorHandler.js', () => {// status→code derivation still runs even without an io channel.expect(res.json.mock.calls[0][0].code).toBe('NOT_FOUND');});++ // `validateRequest` sets `context.details` to the full mapped Zod issue+ // array, so JSON.stringify-ing it emitted a multi-KB blob per 400 —+ // against the single-line logging convention. The log line must summarize;+ // the RESPONSE body must still carry every entry.+ it('summarizes a long details array into one line without stringifying it', async () => {+ const { req, res } = makeReqRes(null);+ const details = Array.from({ length: 12 }, (_, i) => ({+ path: `body.field${i}`,+ message: 'Required'+ }));++ await asyncHandler(async () => {+ throw new ServerError('Validation failed', {+ status: 400,+ code: 'VALIDATION_ERROR',+ context: { details }+ });+ })(req, res, vi.fn());+ await flushMicrotasks();++ expect(errorSpy).toHaveBeenCalledTimes(1);+ const [line, ...extraArgs] = errorSpy.mock.calls[0];+ expect(extraArgs).toEqual([]);+ expect(line).not.toContain('\n');+ expect(line).not.toContain('[{');+ expect(line).not.toContain('"path"');+ expect(line).toContain('body.field0: Required');+ expect(line).toContain('body.field4: Required');+ expect(line).not.toContain('body.field5');+ expect(line).toContain('(+7 more)');++ // Logging-only change: the envelope still carries the full array.+ expect(res.json.mock.calls[0][0].context.details).toEqual(details);+ });++ // dbAdmin puts raw pg_dump/pg_restore stderr in the same field.+ it('collapses a multi-line string details value to one truncated line', async () => {+ const { req, res } = makeReqRes(null);+ const details = `pg_dump: error: connection to server failed\n${'x'.repeat(500)}\ntrailing`;++ await asyncHandler(async () => {+ throw new ServerError('Export failed', { status: 400, context: { details } });+ })(req, res, vi.fn());+ await flushMicrotasks();++ const line = errorSpy.mock.calls[0][0];+ expect(line).not.toContain('\n');+ expect(line).toContain('pg_dump: error: connection to server failed');+ expect(line).not.toContain('trailing');+ expect(line.endsWith('…')).toBe(true);+ });++ // The 500 branch logs the stack, not `details` — it must stay untouched.+ it('leaves the 500 stack branch alone', async () => {+ const { req, res } = makeReqRes(null);+ const error = new ServerError('boom', { status: 500, context: { details: [{ path: 'a', message: 'b' }] } });++ await asyncHandler(async () => { throw error; })(req, res, vi.fn());+ await flushMicrotasks();++ expect(errorSpy).toHaveBeenCalledTimes(1);+ const [line, stack] = errorSpy.mock.calls[0];+ expect(line).not.toContain('a: b');+ expect(stack).toBe(error.stack);+ });});describe('sendErrorResponse', () => {