@@ -163,7 +163,7 @@ trait NodeViewHolder[TX <: Transaction, PMOD <: PersistentNodeViewModifier]
163
163
}
164
164
}
165
165
166
- private def requestDownloads (pi : ProgressInfo [PMOD ]): Unit =
166
+ protected def requestDownloads (pi : ProgressInfo [PMOD ]): Unit =
167
167
pi.toDownload.foreach { case (tid, id) =>
168
168
context.system.eventStream.publish(DownloadRequest (tid, id))
169
169
}
@@ -206,7 +206,7 @@ trait NodeViewHolder[TX <: Transaction, PMOD <: PersistentNodeViewModifier]
206
206
**/
207
207
208
208
@ tailrec
209
- private def updateState (history : HIS ,
209
+ protected final def updateState (history : HIS ,
210
210
state : MS ,
211
211
progressInfo : ProgressInfo [PMOD ],
212
212
suffixApplied : IndexedSeq [PMOD ]): (HIS , Try [MS ], Seq [PMOD ]) = {
@@ -222,14 +222,18 @@ trait NodeViewHolder[TX <: Transaction, PMOD <: PersistentNodeViewModifier]
222
222
223
223
stateToApplyTry match {
224
224
case Success (stateToApply) =>
225
- val stateUpdateInfo = applyState(history, stateToApply, suffixTrimmed, progressInfo)
226
-
227
- stateUpdateInfo.failedMod match {
228
- case Some (_) =>
229
- @ SuppressWarnings (Array (" org.wartremover.warts.OptionPartial" ))
230
- val alternativeProgressInfo = stateUpdateInfo.alternativeProgressInfo.get
231
- updateState(stateUpdateInfo.history, stateUpdateInfo.state, alternativeProgressInfo, stateUpdateInfo.suffix)
232
- case None => (stateUpdateInfo.history, Success (stateUpdateInfo.state), stateUpdateInfo.suffix)
225
+ applyState(history, stateToApply, suffixTrimmed, progressInfo) match {
226
+ case Success (stateUpdateInfo) =>
227
+ stateUpdateInfo.failedMod match {
228
+ case Some (_) =>
229
+ @ SuppressWarnings (Array (" org.wartremover.warts.OptionPartial" ))
230
+ val alternativeProgressInfo = stateUpdateInfo.alternativeProgressInfo.get
231
+ updateState(stateUpdateInfo.history, stateUpdateInfo.state, alternativeProgressInfo, stateUpdateInfo.suffix)
232
+ case None =>
233
+ (stateUpdateInfo.history, Success (stateUpdateInfo.state), stateUpdateInfo.suffix)
234
+ }
235
+ case Failure (ex) =>
236
+ (history, Failure (ex), suffixTrimmed)
233
237
}
234
238
case Failure (e) =>
235
239
log.error(" Rollback failed: " , e)
@@ -239,24 +243,30 @@ trait NodeViewHolder[TX <: Transaction, PMOD <: PersistentNodeViewModifier]
239
243
}
240
244
}
241
245
242
- protected def applyState (history : HIS ,
246
+ private def applyState (history : HIS ,
243
247
stateToApply : MS ,
244
248
suffixTrimmed : IndexedSeq [PMOD ],
245
- progressInfo : ProgressInfo [PMOD ]): UpdateInformation = {
249
+ progressInfo : ProgressInfo [PMOD ]): Try [ UpdateInformation ] = {
246
250
val updateInfoSample = UpdateInformation (history, stateToApply, None , None , suffixTrimmed)
247
- progressInfo.toApply.foldLeft(updateInfoSample) { case (updateInfo, modToApply) =>
248
- if (updateInfo.failedMod.isEmpty) {
249
- updateInfo.state.applyModifier(modToApply) match {
250
- case Success (stateAfterApply) =>
251
- val newHis = history.reportModifierIsValid(modToApply)
252
- context.system.eventStream.publish(SemanticallySuccessfulModifier (modToApply))
253
- UpdateInformation (newHis, stateAfterApply, None , None , updateInfo.suffix :+ modToApply)
254
- case Failure (e) =>
255
- val (newHis, newProgressInfo) = history.reportModifierIsInvalid(modToApply, progressInfo)
256
- context.system.eventStream.publish(SemanticallyFailedModification (modToApply, e))
257
- UpdateInformation (newHis, updateInfo.state, Some (modToApply), Some (newProgressInfo), updateInfo.suffix)
258
- }
259
- } else updateInfo
251
+ progressInfo.toApply.foldLeft[Try [UpdateInformation ]](Success (updateInfoSample)) {
252
+ case (f@ Failure (ex), _) =>
253
+ log.error(" Reporting modifier failed" , ex)
254
+ f
255
+ case (success@ Success (updateInfo), modToApply) =>
256
+ if (updateInfo.failedMod.isEmpty) {
257
+ updateInfo.state.applyModifier(modToApply) match {
258
+ case Success (stateAfterApply) =>
259
+ history.reportModifierIsValid(modToApply).map { newHis =>
260
+ context.system.eventStream.publish(SemanticallySuccessfulModifier (modToApply))
261
+ UpdateInformation (newHis, stateAfterApply, None , None , updateInfo.suffix :+ modToApply)
262
+ }
263
+ case Failure (e) =>
264
+ history.reportModifierIsInvalid(modToApply, progressInfo).map { case (newHis, newProgressInfo) =>
265
+ context.system.eventStream.publish(SemanticallyFailedModification (modToApply, e))
266
+ UpdateInformation (newHis, updateInfo.state, Some (modToApply), Some (newProgressInfo), updateInfo.suffix)
267
+ }
268
+ }
269
+ } else success
260
270
}
261
271
}
262
272
@@ -294,8 +304,8 @@ trait NodeViewHolder[TX <: Transaction, PMOD <: PersistentNodeViewModifier]
294
304
295
305
case Failure (e) =>
296
306
log.warn(s " Can`t apply persistent modifier (id: ${pmod.encodedId}, contents: $pmod) to minimal state " , e)
307
+ // not publishing SemanticallyFailedModification as this is an internal error
297
308
updateNodeView(updatedHistory = Some (newHistory))
298
- context.system.eventStream.publish(SemanticallyFailedModification (pmod, e))
299
309
}
300
310
} else {
301
311
requestDownloads(progressInfo)
0 commit comments