From e63f39f26f783fe3c6499a13bd52a1ebd59a5376 Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Thu, 27 Nov 2025 15:17:37 +0100 Subject: [PATCH] cleaner errors --- typescript-client/sqlUtils.ts | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/typescript-client/sqlUtils.ts b/typescript-client/sqlUtils.ts index 99aeeb59cc..816aa2bfa1 100644 --- a/typescript-client/sqlUtils.ts +++ b/typescript-client/sqlUtils.ts @@ -94,10 +94,13 @@ function sqlProviderImpl( let content = values.map((_, i) => formatArg(i)).join("\n") + "\n"; if (provider === "ducklake") content += `ATTACH 'ducklake://${name}' AS dl;USE dl;\n`; + + let contentBody = ""; for (let i = 0; i < strings.length; i++) { - content += strings[i]; - if (i !== strings.length - 1) content += `$${i + 1}`; + contentBody += strings[i]; + if (i !== strings.length - 1) contentBody += `$${i + 1}`; } + content += contentBody; const args = { ...Object.fromEntries(values.map((v, i) => [`arg${i + 1}`, v])), @@ -113,11 +116,29 @@ function sqlProviderImpl( }: FetchParams = {}) { if (resultCollection) content = `-- result_collection=${resultCollection}\n${content}`; - let result = await JobService.runScriptPreviewInline({ - workspace: getWorkspace(), - requestBody: { args, content, language }, - }); - return result as SqlResult; + try { + let result = await JobService.runScriptPreviewInline({ + workspace: getWorkspace(), + requestBody: { args, content, language }, + }); + return result as SqlResult; + } catch (e: any) { + let err = e; + if ( + e && + typeof e.body == "string" && + e.statusText == "Internal Server Error" + ) { + let body = e.body; + if (body.startsWith("Internal:")) body = body.slice(9).trim(); + if (body.startsWith("Error:")) body = body.slice(6).trim(); + if (body.startsWith("datatable")) body = body.slice(9).trim(); + err = Error(`${provider} ${body}`); + err.query = contentBody; + err.request = e.request; + } + throw err; + } } return {