mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-09 23:17:59 -05:00
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:
committed by
Siddharth Ganesan
parent
d58ceb4bce
commit
2771c688ff
@@ -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`
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user