Skip to content

Commit 95803f8

Browse files
committed
Process error when running auto-open last document
1 parent 55c45d0 commit 95803f8

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

ganttproject/src/main/java/biz/ganttproject/storage/Document.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import net.sourceforge.ganttproject.document.FileDocument
4141
import net.sourceforge.ganttproject.document.ProxyDocument
4242
import net.sourceforge.ganttproject.document.webdav.WebDavStorageImpl
4343
import net.sourceforge.ganttproject.gui.ProjectUIFacade
44+
import net.sourceforge.ganttproject.gui.UIFacade
4445
import net.sourceforge.ganttproject.storage.BaseTxnId
4546
import org.xml.sax.SAXException
4647
import java.io.File
@@ -341,13 +342,21 @@ fun String.asDocumentUrl(): Pair<URL, String> =
341342
}
342343

343344
// Tries to open the most recent document, if the corresponding option is switched on.
344-
fun maybeOpenLastDocument(project: IGanttProject, projectUIFacade: ProjectUIFacade) {
345+
fun maybeOpenLastDocument(project: IGanttProject, uiFacade: UIFacade, projectUIFacade: ProjectUIFacade) {
345346
if (!reopenLastFileOption.isChecked) {
346347
return
347348
}
348349
val recentDocsConsumer = Consumer<List<RecentDocAsFolderItem>> { docList ->
349350
docList.firstOrNull()?.asDocument()?.let {
350-
projectUIFacade.openProject(project.documentManager.getProxyDocument(it), project, null, null)
351+
val stateMachine = projectUIFacade.openProject(project.documentManager.getProxyDocument(it), project, null, null)
352+
stateMachine.stateFailed.await {
353+
LOG.error("{}: {}", it.errorTitle, it.errorDescription, exception = it.throwable)
354+
uiFacade.showErrorDialog("""
355+
# ${it.errorTitle}
356+
----
357+
${it.errorDescription}
358+
""".trimIndent())
359+
}
351360
}
352361
}
353362
val busyIndicator = Consumer<Boolean> { }
@@ -405,4 +414,4 @@ fun DocumentManager.loadRecentDocs(
405414
}
406415
}
407416

408-
private val LOG = GPLogger.create("Document")
417+
private val LOG = GPLogger.create("Document")

ganttproject/src/main/java/net/sourceforge/ganttproject/gui/ProjectOpenStrategy.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ internal class CommandLineProjectOpenStrategy(
483483
if (path != null) {
484484
doOpenStartupDocument(path)
485485
} else {
486-
maybeOpenLastDocument(project, projectUiFacade)
486+
maybeOpenLastDocument(project, uiFacade, projectUiFacade)
487487
}
488488
}
489489
private fun doOpenStartupDocument(path: String) {
@@ -536,4 +536,4 @@ internal class CommandLineProjectOpenStrategy(
536536
}
537537

538538
private val DOCUMENT_LOGGER = GPLogger.create("Document.Info")
539-
private val DOCUMENT_ERROR_LOGGER = GPLogger.create("Document.Error")
539+
private val DOCUMENT_ERROR_LOGGER = GPLogger.create("Document.Error")

ganttproject/src/main/java/net/sourceforge/ganttproject/storage/SqlDatabaseUtils.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ fun runStatements(dataSource: DataSource, statements: List<String>) {
2828
${statements.joinToString(separator = ";\n")};
2929
""".trimIndent()
3030
println("Running \n $sqlScript")
31-
runScript(dataSource, sqlScript)
31+
dataSource.connection.use { cnx ->
32+
statements.forEach { query ->
33+
cnx.createStatement().use { stmt ->
34+
try {
35+
stmt.execute(query)
36+
} catch (e: Exception) {
37+
throw ProjectDatabaseException("Failed to execute statement: $query", e)
38+
}
39+
}
40+
}
41+
cnx.commit()
42+
}
3243
}
3344

3445
fun runScriptFromResource(dataSource: DataSource, path: String) {

0 commit comments

Comments
 (0)