Skip to content

Commit

Permalink
Better SQL error handling
Browse files Browse the repository at this point in the history
Update issue #2514
  • Loading branch information
dbarashev committed Sep 27, 2024
1 parent 19e22f7 commit 7b07d54
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion biz.ganttproject.app.localization
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class CalculationMethodValidator(private val projectDatabase: ProjectDatabase) {
try {
projectDatabase.validateColumnConsumer(ColumnConsumer(calculationMethod) {_,_->})
} catch (ex: ProjectDatabaseException) {
//GPLogger.create("ProjectDatabase").error("calculation method validation failed: ${ex.message}", ex)
throw ValidationException(RootLocalizer.formatText("option.customPropertyDialog.expression.validation.syntax"))
//GPLogger.create("ProjectDatabase").error("calculation method validation failed: ${ex.reason}", exception = ex)
//ex.printStackTrace(System.out)
throw ValidationException(RootLocalizer.formatText("option.customPropertyDialog.expression.validation.syntax", ex.reason))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ internal open class ItemEditorPane<T: Item<T>>(
internal val propertySheet = PropertySheetBuilder(localizer).createPropertySheet(fields)
private val errorLabel = Label().also {
it.styleClass.addAll("hint", "hint-validation")
it.isWrapText = true
}
private val errorPane = HBox().also {
it.styleClass.addAll("hint-validation-pane", "noerror")
Expand Down Expand Up @@ -291,11 +292,6 @@ internal class ItemListDialogPane<T: Item<T>>(
internal val listView: ListView<T> = ListView()

init {
// selectedItem.addWatcher { evt ->
// if (evt.trigger != listView && evt.newValue != null) {
// listItems.replaceAll { if (it == evt.newValue?.cloneOf) { evt.newValue?.clone(forEditing = false) } else { it } }
// }
// }
listView.apply {
this@ItemListDialogPane.dialogModel.selection = { selectionModel.selectedItems }
items = listItems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,32 @@ import biz.ganttproject.customproperty.SimpleSelect
import biz.ganttproject.storage.db.tables.records.TaskRecord
import net.sourceforge.ganttproject.task.Task
import net.sourceforge.ganttproject.task.dependency.TaskDependency
import org.h2.jdbc.JdbcException
import java.awt.Color

private val SYNTAX_ERROR_PREFIX = """Syntax error in SQL statement """"
open class ProjectDatabaseException: Exception {
constructor(message: String): super(message)
constructor(message: String, cause: Throwable): super(message, cause)

val reason: String get() =
this.cause?.let {
if (it.cause is JdbcException) {
var message = (it.cause as Throwable).message!!
val hasSqlStatement = message.indexOf("; SQL statement:")
if (hasSqlStatement != -1) {
return message.substring(0 until hasSqlStatement)
}
if (message.startsWith(SYNTAX_ERROR_PREFIX)) {
val posMarker = message.indexOf("[*]")
if (posMarker != -1) {
return message.substring(SYNTAX_ERROR_PREFIX.length until posMarker)
}
}
message
} else null
} ?: this.message ?: ""

}

interface ProjectDatabaseTxn {
Expand Down

0 comments on commit 7b07d54

Please sign in to comment.