Skip to content

Commit 30c486f

Browse files
author
Oleksandr Dzhychko
authored
Merge pull request #985 from modelix/fix/show-exceptions-in-MPSBulkSynchronizer
fix(bulk-model-sync): propagate all exceptions thrown while running commands in MPS
2 parents 56c1827 + f2c2740 commit 30c486f

File tree

1 file changed

+26
-41
lines changed

1 file changed

+26
-41
lines changed

bulk-model-sync-mps/src/main/kotlin/org/modelix/mps/model/sync/bulk/MPSBulkSynchronizer.kt

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import kotlinx.serialization.json.Json
3535
import kotlinx.serialization.json.decodeFromStream
3636
import org.jetbrains.annotations.VisibleForTesting
3737
import org.jetbrains.mps.openapi.model.EditableSModel
38-
import org.jetbrains.mps.openapi.module.ModelAccess
3938
import org.jetbrains.mps.openapi.module.SModule
4039
import org.jetbrains.mps.openapi.module.SRepository
4140
import org.modelix.model.api.INode
@@ -195,40 +194,34 @@ object MPSBulkSynchronizer {
195194
continueOnError: Boolean,
196195
getModulesToImport: () -> Sequence<ExistingAndExpectedNode>,
197196
) {
198-
val access = repository.modelAccess
199-
ThreadUtils.runInUIThreadAndWait {
200-
access.executeCommand {
201-
println("Importing modules...")
202-
try {
203-
println("Importing modules...")
204-
// `modulesToImport` lazily produces modules to import
205-
// so that loaded model data can be garbage collected.
206-
val modulesToImport = getModulesToImport()
207-
ModelImporter(rootOfImport, continueOnError).importIntoNodes(modulesToImport)
208-
println("Import finished.")
209-
} catch (ex: Exception) {
210-
// Exceptions are only visible in the MPS log file by default
211-
ex.printStackTrace()
212-
}
213-
println("Import finished.")
214-
}
197+
executeCommandWithExceptionHandling(repository) {
198+
println("Importing modules...")
199+
// `modulesToImport` lazily produces modules to import
200+
// so that loaded model data can be garbage collected.
201+
val modulesToImport = getModulesToImport()
202+
ModelImporter(rootOfImport, continueOnError).importIntoNodes(modulesToImport)
203+
println("Import finished.")
215204
}
216205

217-
persistChanges(access, repository)
206+
persistChanges(repository)
218207
}
219208

220-
private fun persistChanges(
221-
access: ModelAccess,
222-
repository: SRepository,
223-
) {
224-
ThreadUtils.runInUIThreadAndWait {
225-
println("Persisting changes...")
226-
access.executeCommand {
227-
enableWorkaroundForFilePerRootPersistence(repository)
228-
updateUnsetResolveInfo(repository)
229-
repository.saveAll()
209+
private fun persistChanges(repository: SRepository) = executeCommandWithExceptionHandling(repository) {
210+
println("Persisting changes...")
211+
enableWorkaroundForFilePerRootPersistence(repository)
212+
updateUnsetResolveInfo(repository)
213+
repository.saveAll()
214+
println("Changes persisted.")
215+
}
216+
217+
private fun executeCommandWithExceptionHandling(repository: SRepository, block: () -> Unit) {
218+
val exception = ThreadUtils.runInUIThreadAndWait {
219+
repository.modelAccess.executeCommand {
220+
block()
230221
}
231-
println("Changes persisted.")
222+
}
223+
if (exception != null) {
224+
throw exception
232225
}
233226
}
234227

@@ -242,7 +235,6 @@ object MPSBulkSynchronizer {
242235

243236
val includedModuleNames = parseRawPropertySet(System.getProperty("modelix.mps.model.sync.bulk.input.modules"))
244237
val includedModulePrefixes = parseRawPropertySet(System.getProperty("modelix.mps.model.sync.bulk.input.modules.prefixes"))
245-
val continueOnError = System.getProperty("modelix.mps.model.sync.bulk.input.continueOnError", "false").toBoolean()
246238

247239
val includedModulesFilter = IncludedModulesFilter(includedModuleNames, includedModulePrefixes)
248240

@@ -261,8 +253,7 @@ object MPSBulkSynchronizer {
261253
}
262254
println("Loading version ${version.getContentHash()}")
263255

264-
val access = repository.modelAccess
265-
access.executeCommandInEDT {
256+
executeCommandWithExceptionHandling(repository) {
266257
val invalidationTree = InvalidationTree(1_000_000)
267258
val newTree = version.getTree()
268259
newTree.visitChanges(
@@ -277,17 +268,11 @@ object MPSBulkSynchronizer {
277268
MPSRepositoryAsNode(repository),
278269
NodeAssociationToMps(MPSArea(repository)),
279270
)
280-
try {
281-
synchronizer.synchronize()
282-
} catch (e: Exception) {
283-
// Exceptions are only visible in the MPS log file by default
284-
e.printStackTrace()
285-
throw e
286-
}
271+
synchronizer.synchronize()
287272
}
288273
}
289274
println("Import finished.")
290-
persistChanges(access, repository)
275+
persistChanges(repository)
291276
}
292277

293278
/**

0 commit comments

Comments
 (0)