{"record":{"id":"719e16622a06d9a8","repo":"windmill-labs/windmill","slug":"extracterrormessage-result","errorCode":null,"errorMessage":"${extractErrorMessage(result)}","messagePattern":"\\$\\{extractErrorMessage\\(result\\)\\}","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/commands/datatable/serve.ts","lineNumber":780,"sourceCode":"  const content = `-- raw_output\\n${await prepareQueryForDatatableProxy(\n    workspaceId,\n    datatableName,\n    query,\n  )}`;\n\n  const jobId = await wmill.runScriptPreview({\n    workspace: workspaceId,\n    requestBody: {\n      content,\n      language: \"postgresql\",\n      args: { database: `datatable://${datatableName}` },\n    },\n  });\n\n  const { result, success } = await pollJobWithQueueLogging(workspaceId, jobId);\n\n  if (!success) {\n    throw createPgProtocolError(extractErrorMessage(result));\n  }\n\n  return coerceEnvelope(result);\n}\n\nasync function prepareQueryForDatatableProxy(\n  workspaceId: string,\n  datatableName: string,\n  query: string,\n): Promise<string> {\n  if (!queryTouchesVirtualDatabaseCatalog(query)) {\n    return query;\n  }\n\n  let databaseNames = [datatableName];\n  if (query.toLowerCase().includes(\"pg_database\")) {\n    try {\n      const items = await wmill.listDataTables({","sourceCodeStart":762,"sourceCodeEnd":798,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/cli/src/commands/datatable/serve.ts#L762-L798","documentation":"The datatable proxy executes each incoming SQL query by running a preview PostgreSQL script on the Windmill workspace (runScriptPreview) and polling the job. If the job completes without success, the server extracts the error message from the job result and surfaces it to the SQL client as a PostgreSQL protocol error. This wraps any SQL execution failure on the Windmill side — bad SQL, missing datatable, permission or resource problems.","triggerScenarios":"runQueryEnvelope polls a script-preview job with pollJobWithQueueLogging and receives success=false; extractErrorMessage(result) is thrown verbatim. Causes include invalid SQL syntax, referencing a non-existent table/datatable, the workspace or datatable path being wrong, and worker execution failures.","commonSituations":"Typo'd SQL sent from psql/DBeaver through the proxy; querying a datatable that was deleted or renamed; the connected user lacking permission to run preview scripts in the workspace; worker queue failures/timeouts surfacing as SQL errors.","solutions":["Read the embedded message — it is the actual error from the Windmill script run (e.g. Postgres syntax error) and fix the SQL accordingly.","Verify the datatable name and workspace: run `wmill datatable list` / check the table exists in the UI.","Check the worker/job logs in the Windmill UI for the failed preview script to see the full stack.","Confirm you are logged into the correct workspace (`wmill workspace current`) and have permission to run scripts there."],"exampleFix":"-- before\nSELECT * FROM custumers LIMIT 10;\n\n-- after\nSELECT * FROM customers LIMIT 10;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const res = await client.query(sql);\n} catch (e) {\n  // message is the raw Windmill job error; log it and inspect the failed\n  // preview-script job in the Windmill UI for the full stack\n  console.error('datatable query failed:', e.message);\n  throw e;\n}","preventionTips":["Validate SQL against the datatable schema before running (check table names in the UI).","Confirm the datatable and workspace still exist and your token has script-run permission.","Keep queries small first (LIMIT) to isolate syntax vs data errors.","Watch worker logs in the Windmill UI for queue/execution failures."],"tags":["postgresql","sql-execution","windmill","cli"],"backgroundTag":"sql-execution-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}