[object Object]

← back to Corvette Dashboard Viewer

Harden fallback (guard snapshot JSON.parse against process crash) + honest feed cap (contrarian gate)

8bbdd4dea141bab41a9f3ffa00e9120df557e82a · 2026-07-28 08:50:52 -0700 · Steve Abrams

Files touched

Diff

commit 8bbdd4dea141bab41a9f3ffa00e9120df557e82a
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Tue Jul 28 08:50:52 2026 -0700

    Harden fallback (guard snapshot JSON.parse against process crash) + honest feed cap (contrarian gate)
---
 public/index.html | 3 ++-
 server.js         | 5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/public/index.html b/public/index.html
index d3b5ed0..3d2412d 100644
--- a/public/index.html
+++ b/public/index.html
@@ -244,7 +244,8 @@ function init(){
 function render(){
   const feed=document.getElementById('feed'); feed.innerHTML='';
   const rows=DATA.filter(p=>!activeFilter||p.color===activeFilter);
-  document.getElementById('feedCnt').textContent=rows.length+' / '+DATA.length+' SKU';
+  const shown=Math.min(rows.length,120);
+  document.getElementById('feedCnt').textContent='showing '+shown+' / '+rows.length+' SKU';
   rows.slice(0,120).forEach(p=>{
     const total=p.palette.reduce((a,c)=>a+c.pct,0)||1;
     const pal=p.palette.map(c=>`<div class="sw2" style="flex:${c.pct};background:${c.hex}"><span>${c.pct}%</span></div>`).join('');
diff --git a/server.js b/server.js
index 38d5765..12a6bfb 100644
--- a/server.js
+++ b/server.js
@@ -55,7 +55,10 @@ http.createServer((req, res) => {
       if (!err && json) { res.writeHead(200, { 'Content-Type': 'application/json', 'X-Data-Source': 'live' }); return res.end(json); }
       fs.readFile(path.join(ROOT, 'data.json'), (e, buf) => {
         if (e) { res.writeHead(502); return res.end('no live db and no snapshot'); }
-        const arr = JSON.parse(buf);
+        // Guard the parse: a corrupt snapshot must not throw in this async callback
+        // and crash the whole process — that would turn the safety net into an outage.
+        let arr;
+        try { arr = JSON.parse(buf); } catch (pe) { res.writeHead(502); return res.end('snapshot unreadable: ' + pe.message); }
         res.writeHead(200, { 'Content-Type': 'application/json', 'X-Data-Source': 'snapshot' });
         res.end(JSON.stringify({ records: arr, totals: null }));
       });

← 15efc4e Make console dynamic: live /api/data (shopify_color_enrichme  ·  back to Corvette Dashboard Viewer  ·  auto-save: 2026-07-28T08:58:52 (2 files) — server.js public/ c665d54 →