Skip to content

Commit d14e03b

Browse files
committed
fix(database): improve error handling in SQL execution
Return meaningful error messages when SQL file is not found, not a SQL file, or execution fails. This enhances debugging and user feedback.
1 parent 54e36f8 commit d14e03b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

exts/ext-database/src/main/kotlin/cc/unitmesh/database/provider/SqlRunService.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ class SqlRunService : RunService {
2828
isFromToolAction: Boolean
2929
): String? {
3030
val sql = runReadAction { PsiManager.getInstance(project).findFile(virtualFile) } as? SqlFile
31-
?: return null
31+
?: return "<DevInsError> SQL: cannot find PSI file"
3232

33-
if (sql.fileType !is SqlFileType) return null
33+
if (sql.fileType !is SqlFileType) return "<DevInsError> SQL: not a SQL file"
3434
val content = runReadAction { sql.text }
35-
return DatabaseSchemaAssistant.executeSqlQuery(project, content)
35+
try {
36+
return DatabaseSchemaAssistant.executeSqlQuery(project, content)
37+
} catch (e: Exception) {
38+
return "<DevInsError> SQL: ${e.message}"
39+
}
3640
}
3741

3842
override fun runConfigurationClass(project: Project): Class<out RunProfile>? =

0 commit comments

Comments
 (0)