From 2be1e5426ad9f37528403c7011ca94681dc3f178 Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Mon, 21 Sep 2026 20:36:30 +0800 Subject: [PATCH 1/2] fix: keep scalar json logs instead of dropping them When LOG_EXECUTION_ID is set we rewrite every stdout/stderr write into a structured log entry, and we treated anything JSON.parse accepts as a log object to hang the labels off. Numbers, booleans, null and json strings parse fine but have no properties, so the 'in' check in getJSONWithContext threw and console silently swallowed it - the line the user logged just vanished. Only take the structured path for objects. --- src/logger.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/logger.ts b/src/logger.ts index 515fa18ed..79676cd3b 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -183,9 +183,17 @@ function processData(data: Uint8Array | string, encoding?: BufferEncoding) { // strip any leading ANSI color codes from the decoded data // to parse colored JSON objects correctly decodedData = decodedData.replace(/\x1b[[(?);]{0,2}(;?\d)*./g, ''); + let parsedData; try { - return {isJSON: true, processedData: JSON.parse(decodedData)}; + parsedData = JSON.parse(decodedData); } catch (e) { return {isJSON: false, processedData: decodedData}; } + // Numbers, booleans, null and JSON strings parse successfully but they are + // not log objects, so there is nowhere to attach the context fields added by + // getJSONWithContext. Log them as plain text instead. + if (typeof parsedData !== 'object' || parsedData === null) { + return {isJSON: false, processedData: decodedData}; + } + return {isJSON: true, processedData: parsedData}; } From df3777151874a60aece1c3bc3e73b4ce7e15b290 Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Mon, 21 Sep 2026 20:36:33 +0800 Subject: [PATCH 2/2] add regression tests for number/bool/null/string log values These four used to throw inside the logger and lose the log line. Also checked they fail on the previous commit. --- test/logger.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/logger.ts b/test/logger.ts index 4b9f3f062..a3e5427d2 100644 --- a/test/logger.ts +++ b/test/logger.ts @@ -86,6 +86,41 @@ describe('getModifiedData', () => { assert.equal(modifiedData, expectedJSONOutput); }); + it('json number value', () => { + const modifiedData = getModifiedData('42'); + assert.equal( + modifiedData, + JSON.stringify(Object.assign({message: '42'}, expectedMetadata)) + '\n', + ); + }); + + it('json boolean value', () => { + const modifiedData = getModifiedData('true'); + assert.equal( + modifiedData, + JSON.stringify(Object.assign({message: 'true'}, expectedMetadata)) + + '\n', + ); + }); + + it('json null value', () => { + const modifiedData = getModifiedData('null'); + assert.equal( + modifiedData, + JSON.stringify(Object.assign({message: 'null'}, expectedMetadata)) + + '\n', + ); + }); + + it('json string value', () => { + const modifiedData = getModifiedData('"abc"'); + assert.equal( + modifiedData, + JSON.stringify(Object.assign({message: '"abc"'}, expectedMetadata)) + + '\n', + ); + }); + it('json with user label', () => { const data = JSON.stringify({ text: 'default text.',