From 99e9c15e912e924785cdc54a8da8e1f78818f807 Mon Sep 17 00:00:00 2001 From: MH4GF Date: Thu, 9 Oct 2025 18:46:11 +0900 Subject: [PATCH] feat: add Sentry error capturing to schemaDesignTool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wrap the schemaDesignTool function with withSentryCaptureException to automatically capture and report errors to Sentry. This enables monitoring of DDL generation errors, schema retrieval errors, patch operation errors, and version creation errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../src/db-agent/tools/schemaDesignTool.ts | 115 +++++++++--------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/frontend/internal-packages/agent/src/db-agent/tools/schemaDesignTool.ts b/frontend/internal-packages/agent/src/db-agent/tools/schemaDesignTool.ts index ac75cc5acd..4049f4bb5b 100644 --- a/frontend/internal-packages/agent/src/db-agent/tools/schemaDesignTool.ts +++ b/frontend/internal-packages/agent/src/db-agent/tools/schemaDesignTool.ts @@ -10,6 +10,7 @@ import { } from '@liam-hq/schema' import * as v from 'valibot' import { toJsonSchema } from '../../utils/jsonSchema' +import { withSentryCaptureException } from '../../utils/withSentryCaptureException' import { getToolConfigurable } from '../getToolConfigurable' const schemaDesignToolSchema = v.object({ @@ -69,65 +70,67 @@ const validateAndExecuteDDL = async ( export const schemaDesignTool: StructuredTool = tool( async (input: unknown, config: RunnableConfig): Promise => { - const toolConfigurableResult = getToolConfigurable(config) - if (toolConfigurableResult.isErr()) { - return `Configuration error: ${toolConfigurableResult.error.message}. Please check the tool configuration and try again.` - } - const { repositories, buildingSchemaId, designSessionId } = - toolConfigurableResult.value - const parsed = v.safeParse(schemaDesignToolSchema, input) - if (!parsed.success) { - const errorDetails = parsed.issues - .map((issue) => `${issue.path?.join('.')}: ${issue.message}`) - .join(', ') - return `Input validation failed: ${errorDetails}. Please check your operations format and ensure all required fields are provided correctly.` - } - - const schemaResult = await repositories.schema.getSchema(designSessionId) - if (schemaResult.isErr()) { - // LangGraph tool nodes require throwing errors to trigger retry mechanism - // eslint-disable-next-line no-throw-error/no-throw-error - throw new Error( - 'Could not retrieve current schema for DDL validation. Please check the schema ID and try again.', + return withSentryCaptureException(async () => { + const toolConfigurableResult = getToolConfigurable(config) + if (toolConfigurableResult.isErr()) { + return `Configuration error: ${toolConfigurableResult.error.message}. Please check the tool configuration and try again.` + } + const { repositories, buildingSchemaId, designSessionId } = + toolConfigurableResult.value + const parsed = v.safeParse(schemaDesignToolSchema, input) + if (!parsed.success) { + const errorDetails = parsed.issues + .map((issue) => `${issue.path?.join('.')}: ${issue.message}`) + .join(', ') + return `Input validation failed: ${errorDetails}. Please check your operations format and ensure all required fields are provided correctly.` + } + + const schemaResult = await repositories.schema.getSchema(designSessionId) + if (schemaResult.isErr()) { + // LangGraph tool nodes require throwing errors to trigger retry mechanism + // eslint-disable-next-line no-throw-error/no-throw-error + throw new Error( + 'Could not retrieve current schema for DDL validation. Please check the schema ID and try again.', + ) + } + + const applyResult = applyPatchOperations( + schemaResult.value.schema, + parsed.output.operations, ) - } - const applyResult = applyPatchOperations( - schemaResult.value.schema, - parsed.output.operations, - ) - - if (applyResult.isErr()) { - // LangGraph tool nodes require throwing errors to trigger retry mechanism - // eslint-disable-next-line no-throw-error/no-throw-error - throw new Error( - `Failed to apply patch operations before DDL validation: ${applyResult.error.message}`, - ) - } - - const { results } = await validateAndExecuteDDL(applyResult.value) - - const successfulStatements = results.filter( - (result) => result.success, - ).length - const totalStatements = results.length - - const versionResult = await repositories.schema.createVersion({ - buildingSchemaId, - latestVersionNumber: schemaResult.value.latestVersionNumber, - patch: parsed.output.operations, + if (applyResult.isErr()) { + // LangGraph tool nodes require throwing errors to trigger retry mechanism + // eslint-disable-next-line no-throw-error/no-throw-error + throw new Error( + `Failed to apply patch operations before DDL validation: ${applyResult.error.message}`, + ) + } + + const { results } = await validateAndExecuteDDL(applyResult.value) + + const successfulStatements = results.filter( + (result) => result.success, + ).length + const totalStatements = results.length + + const versionResult = await repositories.schema.createVersion({ + buildingSchemaId, + latestVersionNumber: schemaResult.value.latestVersionNumber, + patch: parsed.output.operations, + }) + + if (!versionResult.success) { + const errorMessage = versionResult.error ?? 'Unknown error occurred' + // LangGraph tool nodes require throwing errors to trigger retry mechanism + // eslint-disable-next-line no-throw-error/no-throw-error + throw new Error( + `Failed to create schema version after DDL validation: ${errorMessage}. Please try again.`, + ) + } + + return `Schema successfully updated. The operations have been applied to the database schema, DDL validation successful (${successfulStatements}/${totalStatements} statements executed successfully), and new version created.` }) - - if (!versionResult.success) { - const errorMessage = versionResult.error ?? 'Unknown error occurred' - // LangGraph tool nodes require throwing errors to trigger retry mechanism - // eslint-disable-next-line no-throw-error/no-throw-error - throw new Error( - `Failed to create schema version after DDL validation: ${errorMessage}. Please try again.`, - ) - } - - return `Schema successfully updated. The operations have been applied to the database schema, DDL validation successful (${successfulStatements}/${totalStatements} statements executed successfully), and new version created.` }, { name: 'schemaDesignTool',