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([issue-1836]): stamp standard error envelope on avatar GLB stream errors
[._.]/ Adam Eivyf93efe46c0e3
diff --git a/server/routes/avatar.js b/server/routes/avatar.jsindex 3884d103a0..f5402260a4 100644--- a/server/routes/avatar.js+++ b/server/routes/avatar.js@@ -3,7 +3,7 @@ import { createReadStream } from 'fs';import { stat } from 'fs/promises';import { join } from 'path';import { PATHS, pathExists } from '../lib/fileUtils.js';-import { ServerError } from '../lib/errorHandler.js';+import { ServerError, getErrorCode } from '../lib/errorHandler.js';const router = Router();const AVATAR_DIR = join(PATHS.data, 'avatar');@@ -45,7 +45,16 @@ router.get('/model.glb', async (req, res) => {stream.on('error', (err) => {console.warn(`⚠️ Avatar stream error: ${err.code || err.message}`);if (!res.headersSent) {- res.status(err.code === 'ENOENT' ? 404 : 500).json({ error: 'Avatar model unavailable' });+ // The stream 'error' fires outside the asyncHandler promise chain, so a+ // throw here would crash the process instead of bubbling to+ // errorMiddleware. Emit the SAME { error, code, timestamp } envelope+ // errorMiddleware stamps everywhere else so clients see a consistent shape.+ const status = err.code === 'ENOENT' ? 404 : 500;+ res.status(status).json({+ error: 'Avatar model unavailable',+ code: getErrorCode(status),+ timestamp: Date.now()+ });} else {res.destroy(err);}diff --git a/server/routes/avatar.test.js b/server/routes/avatar.test.jsindex 1e4eee88be..b8e8e8ee51 100644--- a/server/routes/avatar.test.js+++ b/server/routes/avatar.test.js@@ -71,10 +71,15 @@ describe('avatar routes', () => {expect(res.status).toBe(404);// The route sets Content-Type to gltf-binary before piping; res.json() does// not overwrite an existing Content-Type, so the body arrives as text.- expect(JSON.parse(res.text).error).toMatch(/unavailable/i);+ const body = JSON.parse(res.text);+ expect(body.error).toMatch(/unavailable/i);+ // Standard error envelope: { error, code, timestamp } — same shape+ // errorMiddleware stamps everywhere else (regression for issue-1836).+ expect(body.code).toBe('NOT_FOUND');+ expect(typeof body.timestamp).toBe('number');});- it('responds with 500 on non-ENOENT stream error before headers sent', async () => {+ it('responds with 500 + full error envelope on non-ENOENT stream error before headers sent', async () => {pathExists.mockResolvedValue(true);const errStream = new Readable({read() {@@ -89,6 +94,10 @@ describe('avatar routes', () => {const res = await request(buildApp()).get('/api/avatar/model.glb');expect(res.status).toBe(500);+ const body = JSON.parse(res.text);+ expect(body.error).toMatch(/unavailable/i);+ expect(body.code).toBe('INTERNAL_ERROR');+ expect(typeof body.timestamp).toBe('number');});});