Use MigrationErrorPolicy to control what happens when a migration helper encounters an error.
import com.netgrif.application.engine.migration.model.MigrationErrorPolicyMigrationErrorPolicy.continueOnError() // log/cache errors and continue
MigrationErrorPolicy.throwImmediately() // stop on first error
MigrationErrorPolicy.throwAfterLimit(10) // stop after 10 errors
MigrationErrorPolicy.throwAfterProcessing() // process all, then fail if errors existmigrationHelper.withErrorPolicy(MigrationErrorPolicy.throwAfterProcessing()) {
migrationHelper.updateAllCasesCursor({ Case useCase ->
// migration logic
})
}migrationHelper.clearErrors()
migrationHelper.withErrorPolicy(MigrationErrorPolicy.continueOnError()) {
migrationHelper.updateAllCasesCursor({ Case useCase ->
// migration logic
})
}
def errors = migrationHelper.popErrors()
errors.each { error ->
log.warn("${error.entityType} ${error.entityId}: ${error.message}", error.cause)
}migrationHelper.withErrorPolicy(MigrationErrorPolicy.throwAfterLimit(20)) {
migrationHelper.updateAllTasksCursor({ Task task ->
migrationHelper.elasticTaskIndex(task)
})
}import com.netgrif.application.engine.migration.throwable.MigrationErrorException
try {
migrationHelper.withErrorPolicy(MigrationErrorPolicy.throwAfterProcessing()) {
migrationHelper.updateAllCasesCursor({ Case useCase ->
// migration logic
})
}
} catch (MigrationErrorException e) {
log.error("Migration failed with ${e.errors.size()} errors")
e.errors.each { error ->
log.error("${error.entityType} ${error.entityId}: ${error.message}", error.cause)
}
throw e
}migrationHelper.clearErrors() // clears cached errors
migrationHelper.hasErrors() // true if errors exist
migrationHelper.getErrors() // returns errors without clearing
migrationHelper.popErrors() // returns errors and clears cachemigrationHelper.clearErrors()
migrationHelper.withErrorPolicy(MigrationErrorPolicy.throwAfterProcessing()) {
// migration logic
}Use throwAfterProcessing() for most production migrations because it collects a full error report and fails only after all possible records are processed.