From c721ae023d3b03c56a9dde902f36cc6199bdb886 Mon Sep 17 00:00:00 2001 From: Robert Coie Date: Sun, 6 Jul 2025 16:12:05 -0700 Subject: [PATCH] proof against the tsc "noUncheckedIndexedAccess" safety option --- clientSSE.go.tmpl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/clientSSE.go.tmpl b/clientSSE.go.tmpl index 015af8f..cbb7f7a 100644 --- a/clientSSE.go.tmpl +++ b/clientSSE.go.tmpl @@ -80,12 +80,13 @@ const sseResponse = async ( let lines = buffer.split("\n"); for (let i = 0; i < lines.length - 1; i++) { - if (lines[i].length == 0) { + const line = lines[i]; + if (!line || line.length == 0) { continue; } let data: any; try { - data = JSON.parse(lines[i]); + data = JSON.parse(line); if (data.hasOwnProperty("webrpcError")) { const error = data.webrpcError; const code: number = @@ -116,7 +117,8 @@ const sseResponse = async ( } if (!done) { - buffer = lines[lines.length - 1]; + const lastLine = lines[lines.length - 1]; + buffer = lastLine ? lastLine : ""; continue; }