From 8f726c0ac91e595d1ee3af06dc13775847cef038 Mon Sep 17 00:00:00 2001 From: mulahasanovic Date: Wed, 13 May 2026 14:26:12 +0200 Subject: [PATCH] fix(debug): add viya debug log parser - parse JSON from inline blob with webout --- src/utils/parseViyaLogDebugResponse.ts | 13 +++++++++++-- src/utils/spec/parseViyaLogDebugResponse.spec.ts | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/utils/parseViyaLogDebugResponse.ts b/src/utils/parseViyaLogDebugResponse.ts index 96bfc7f..0dfe20e 100644 --- a/src/utils/parseViyaLogDebugResponse.ts +++ b/src/utils/parseViyaLogDebugResponse.ts @@ -1,18 +1,27 @@ import { getValidJson } from './getValidJson' +import { parseWeboutResponse } from './parseWeboutResponse' /** * When querying a Viya job using the Web approach with _DEBUG=log (used when * runAsTask is true), the webout JSON is inlined into the response via: * var blob = new Blob([`{...}`], {type: 'application/json'}); + * On abort/error paths the same shape is used but with text/plain and + * weboutBEGIN/END markers around the JSON: + * var blob = new Blob([`>>weboutBEGIN<<\n{...}\n>>weboutEND<<\n`], {type: 'text/plain'}); * No follow-up request is needed — extract and parse the JSON directly. */ export const parseSasViyaLogDebugResponse = async (response: string) => { const blobMatch = response.match( - /new Blob\(\[`([\s\S]*?)`\],\s*\{type:\s*'application\/json'\}\)/ + /new Blob\(\[`([\s\S]*?)`\],\s*\{type:\s*'(?:application\/json|text\/plain)'\}\)/ ) if (!blobMatch) { throw new Error('Unable to find webout blob in debug log response.') } - return getValidJson(blobMatch[1]) + const blobContent = blobMatch[1] + const stripped = blobContent.includes('>>weboutBEGIN<<') + ? parseWeboutResponse(blobContent) + : blobContent + + return getValidJson(stripped) } diff --git a/src/utils/spec/parseViyaLogDebugResponse.spec.ts b/src/utils/spec/parseViyaLogDebugResponse.spec.ts index 08c5c56..2683d0a 100644 --- a/src/utils/spec/parseViyaLogDebugResponse.spec.ts +++ b/src/utils/spec/parseViyaLogDebugResponse.spec.ts @@ -31,6 +31,20 @@ var blob = new Blob([\`{"SYSDATE" : "13MAY26" expect(result).toEqual(resultData) }) + it('should extract and parse JSON wrapped in weboutBEGIN/END (text/plain blob)', async () => { + const resultData = { SYSCC: '1012', SYSERRORTEXT: 'File missing.' } + const response = `` + + const result = await parseSasViyaLogDebugResponse(response) + + expect(result).toEqual(resultData) + }) + it('should throw an error if blob is not found', async () => { const response = `No blob here`