Skip to content

Commit 42ec18c

Browse files
committed
feat(agents): add onSqlError hook for customizable SQL error logging
Allow users to override onSqlError(query, error) to customize logging behavior for SQL errors instead of using console.error directly. Fixes #767
1 parent efd12f6 commit 42ec18c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/agents/src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ export class Agent<
391391
// Execute the SQL query with the provided values
392392
return [...this.ctx.storage.sql.exec(query, ...values)] as T[];
393393
} catch (e) {
394-
console.error(`failed to execute sql query: ${query}`, e);
394+
this.onSqlError(query, e);
395395
throw this.onError(e);
396396
}
397397
}
@@ -871,6 +871,15 @@ export class Agent<
871871
throw theError;
872872
}
873873

874+
/**
875+
* Handle SQL execution errors. Override this method to customize logging behavior.
876+
* @param query The SQL query that failed
877+
* @param error The error that occurred
878+
*/
879+
onSqlError(query: string, error: unknown): void {
880+
console.error(`failed to execute sql query: ${query}`, error);
881+
}
882+
874883
/**
875884
* Render content (not implemented in base class)
876885
*/

0 commit comments

Comments
 (0)