improvement(supabase): added more verbose error logging for supabase operations (#1035)

* improvement(supabase): added more verbose error logging for supabase operations

* updated docs
This commit is contained in:
Waleed Latif
2025-08-19 13:37:53 -07:00
committed by Siddharth Ganesan
parent d58ceb4bce
commit 2771c688ff
7 changed files with 97 additions and 27 deletions

View File

@@ -142,7 +142,7 @@ Get a single row from a Supabase table based on filter criteria
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `message` | string | Operation status message |
| `results` | object | The row data if found, null if not found |
| `results` | array | Array containing the row data if found, empty array if not found |
### `supabase_update`

View File

@@ -164,8 +164,12 @@ export const SupabaseBlock: BlockConfig<SupabaseResponse> = {
if (data && typeof data === 'string' && data.trim()) {
try {
parsedData = JSON.parse(data)
} catch (_e) {
throw new Error('Invalid JSON data format')
} catch (parseError) {
// Provide more detailed error information
const errorMsg = parseError instanceof Error ? parseError.message : 'Unknown JSON error'
throw new Error(
`Invalid JSON data format: ${errorMsg}. Please check your JSON syntax (e.g., strings must be quoted like "value").`
)
}
} else if (data && typeof data === 'object') {
parsedData = data

View File

@@ -59,28 +59,36 @@ export const deleteTool: ToolConfig<SupabaseDeleteParams, SupabaseDeleteResponse
},
transformResponse: async (response: Response) => {
// Handle empty response from delete operations
const text = await response.text()
let data
if (text?.trim()) {
try {
data = JSON.parse(text)
} catch (e) {
// If we can't parse it, just use the text
data = text
} catch (parseError) {
throw new Error(`Failed to parse Supabase response: ${parseError}`)
}
} else {
// Empty response means successful deletion
data = []
}
const deletedCount = Array.isArray(data) ? data.length : text ? 1 : 0
const deletedCount = Array.isArray(data) ? data.length : 0
if (deletedCount === 0) {
return {
success: true,
output: {
message: 'No rows were deleted (no matching records found)',
results: data,
},
error: undefined,
}
}
return {
success: true,
output: {
message: `Successfully deleted ${deletedCount === 0 ? 'row(s)' : `${deletedCount} row(s)`}`,
message: `Successfully deleted ${deletedCount} row${deletedCount === 1 ? '' : 's'}`,
results: data,
},
error: undefined,

View File

@@ -57,14 +57,21 @@ export const getRowTool: ToolConfig<SupabaseGetRowParams, SupabaseGetRowResponse
},
transformResponse: async (response: Response) => {
const data = await response.json()
const row = data.length > 0 ? data[0] : null
let data
try {
data = await response.json()
} catch (parseError) {
throw new Error(`Failed to parse Supabase response: ${parseError}`)
}
const rowFound = data.length > 0
const results = rowFound ? [data[0]] : []
return {
success: true,
output: {
message: row ? 'Successfully found row' : 'No row found matching the criteria',
results: row,
message: rowFound ? 'Successfully found 1 row' : 'No row found matching the criteria',
results: results,
},
error: undefined,
}
@@ -72,6 +79,9 @@ export const getRowTool: ToolConfig<SupabaseGetRowParams, SupabaseGetRowResponse
outputs: {
message: { type: 'string', description: 'Operation status message' },
results: { type: 'object', description: 'The row data if found, null if not found' },
results: {
type: 'array',
description: 'Array containing the row data if found, empty array if not found',
},
},
}

View File

@@ -53,8 +53,8 @@ export const insertTool: ToolConfig<SupabaseInsertParams, SupabaseInsertResponse
},
transformResponse: async (response: Response) => {
// Handle empty response case
const text = await response.text()
if (!text || text.trim() === '') {
return {
success: true,
@@ -66,12 +66,34 @@ export const insertTool: ToolConfig<SupabaseInsertParams, SupabaseInsertResponse
}
}
const data = JSON.parse(text)
let data
try {
data = JSON.parse(text)
} catch (parseError) {
throw new Error(`Failed to parse Supabase response: ${parseError}`)
}
// Check if results array is empty and provide better feedback
const resultsArray = Array.isArray(data) ? data : [data]
const isEmpty = resultsArray.length === 0 || (resultsArray.length === 1 && !resultsArray[0])
if (isEmpty) {
return {
success: false,
output: {
message: 'No data was inserted into Supabase',
results: data,
},
error:
'No data was inserted into Supabase. This usually indicates invalid data format or schema mismatch. Please check that your JSON is valid and matches your table schema.',
}
}
const insertedCount = resultsArray.length
return {
success: true,
output: {
message: 'Successfully inserted data into Supabase',
message: `Successfully inserted ${insertedCount} row${insertedCount === 1 ? '' : 's'} into Supabase`,
results: data,
},
error: undefined,

View File

@@ -79,12 +79,30 @@ export const queryTool: ToolConfig<SupabaseQueryParams, SupabaseQueryResponse> =
},
transformResponse: async (response: Response) => {
const data = await response.json()
let data
try {
data = await response.json()
} catch (parseError) {
throw new Error(`Failed to parse Supabase response: ${parseError}`)
}
const rowCount = Array.isArray(data) ? data.length : 0
if (rowCount === 0) {
return {
success: true,
output: {
message: 'No rows found matching the query criteria',
results: data,
},
error: undefined,
}
}
return {
success: true,
output: {
message: 'Successfully queried data from Supabase',
message: `Successfully queried ${rowCount} row${rowCount === 1 ? '' : 's'} from Supabase`,
results: data,
},
error: undefined,

View File

@@ -63,28 +63,36 @@ export const updateTool: ToolConfig<SupabaseUpdateParams, SupabaseUpdateResponse
},
transformResponse: async (response: Response) => {
// Handle potentially empty response from update operations
const text = await response.text()
let data
if (text?.trim()) {
try {
data = JSON.parse(text)
} catch (e) {
// If we can't parse it, just use the text
data = text
} catch (parseError) {
throw new Error(`Failed to parse Supabase response: ${parseError}`)
}
} else {
// Empty response means successful update
data = []
}
const updatedCount = Array.isArray(data) ? data.length : text ? 1 : 0
const updatedCount = Array.isArray(data) ? data.length : 0
if (updatedCount === 0) {
return {
success: true,
output: {
message: 'No rows were updated (no matching records found)',
results: data,
},
error: undefined,
}
}
return {
success: true,
output: {
message: `Successfully updated ${updatedCount === 0 ? 'row(s)' : `${updatedCount} row(s)`}`,
message: `Successfully updated ${updatedCount} row${updatedCount === 1 ? '' : 's'}`,
results: data,
},
error: undefined,