Skip to content

Commit 3b3405d

Browse files
committed
Log TSQL execution errors
1 parent 539da4e commit 3b3405d

File tree

1 file changed

+20
-0
lines changed
  • internal-packages/clickhouse/src/client

1 file changed

+20
-0
lines changed

internal-packages/clickhouse/src/client/tsql.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import {
1717
import type { ClickhouseReader, QueryStats } from "./types.js";
1818
import { QueryError } from "./errors.js";
1919
import type { OutputColumnMetadata } from "@internal/tsql";
20+
import { Logger } from "@trigger.dev/core/logger";
21+
22+
const logger = new Logger("tsql", "info");
2023

2124
export type { QueryStats };
2225

@@ -105,6 +108,9 @@ export async function executeTSQL<TOut extends z.ZodSchema>(
105108
): Promise<TSQLQueryResult<z.output<TOut>>> {
106109
const shouldTransformValues = options.transformValues ?? true;
107110

111+
let generatedSql: string | undefined;
112+
let generatedParams: Record<string, unknown> | undefined;
113+
108114
try {
109115
// 1. Compile the TSQL query to ClickHouse SQL
110116
const { sql, params, columns } = compileTSQL(options.query, {
@@ -116,6 +122,9 @@ export async function executeTSQL<TOut extends z.ZodSchema>(
116122
fieldMappings: options.fieldMappings,
117123
});
118124

125+
generatedSql = sql;
126+
generatedParams = params;
127+
119128
// 2. Execute the query with stats
120129
const queryFn = reader.queryWithStats({
121130
name: options.name,
@@ -145,6 +154,17 @@ export async function executeTSQL<TOut extends z.ZodSchema>(
145154

146155
return [null, { rows: rows ?? [], columns, stats }];
147156
} catch (error) {
157+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
158+
159+
// Log TSQL compilation or unexpected errors
160+
logger.error("[TSQL] Query error", {
161+
name: options.name,
162+
error: errorMessage,
163+
tsql: options.query,
164+
generatedSql: generatedSql ?? "(compilation failed)",
165+
generatedParams: generatedParams ?? {},
166+
});
167+
148168
if (error instanceof Error) {
149169
return [new QueryError(error.message, { query: options.query }), null];
150170
}

0 commit comments

Comments
 (0)