Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spotty-donkeys-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"agents": patch
---

add onSqlError hook for customizable SQL error logging
11 changes: 10 additions & 1 deletion packages/agents/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export class Agent<
// Execute the SQL query with the provided values
return [...this.ctx.storage.sql.exec(query, ...values)] as T[];
} catch (e) {
console.error(`failed to execute sql query: ${query}`, e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead why don't we use our logger directly here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or pipe into onError

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with piping, done that

this.onSqlError(query, e);
throw this.onError(e);
}
}
Expand Down Expand Up @@ -871,6 +871,15 @@ export class Agent<
throw theError;
}

/**
* Handle SQL execution errors. Override this method to customize logging behavior.
* @param query The SQL query that failed
* @param error The error that occurred
*/
onSqlError(_query: string, _error: unknown): void {
console.error(`failed to execute sql query: ${_query}`, _error);
}

/**
* Render content (not implemented in base class)
*/
Expand Down
Loading