@@ -163,7 +163,7 @@ trait NodeViewHolder[TX <: Transaction, PMOD <: PersistentNodeViewModifier]
163163 }
164164 }
165165
166- private def requestDownloads (pi : ProgressInfo [PMOD ]): Unit =
166+ protected def requestDownloads (pi : ProgressInfo [PMOD ]): Unit =
167167 pi.toDownload.foreach { case (tid, id) =>
168168 context.system.eventStream.publish(DownloadRequest (tid, id))
169169 }
@@ -206,7 +206,7 @@ trait NodeViewHolder[TX <: Transaction, PMOD <: PersistentNodeViewModifier]
206206 **/
207207
208208 @ tailrec
209- private def updateState (history : HIS ,
209+ protected final def updateState (history : HIS ,
210210 state : MS ,
211211 progressInfo : ProgressInfo [PMOD ],
212212 suffixApplied : IndexedSeq [PMOD ]): (HIS , Try [MS ], Seq [PMOD ]) = {
@@ -222,14 +222,18 @@ trait NodeViewHolder[TX <: Transaction, PMOD <: PersistentNodeViewModifier]
222222
223223 stateToApplyTry match {
224224 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)
233237 }
234238 case Failure (e) =>
235239 log.error(" Rollback failed: " , e)
@@ -239,24 +243,30 @@ trait NodeViewHolder[TX <: Transaction, PMOD <: PersistentNodeViewModifier]
239243 }
240244 }
241245
242- protected def applyState (history : HIS ,
246+ private def applyState (history : HIS ,
243247 stateToApply : MS ,
244248 suffixTrimmed : IndexedSeq [PMOD ],
245- progressInfo : ProgressInfo [PMOD ]): UpdateInformation = {
249+ progressInfo : ProgressInfo [PMOD ]): Try [ UpdateInformation ] = {
246250 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
260270 }
261271 }
262272
@@ -294,8 +304,8 @@ trait NodeViewHolder[TX <: Transaction, PMOD <: PersistentNodeViewModifier]
294304
295305 case Failure (e) =>
296306 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
297308 updateNodeView(updatedHistory = Some (newHistory))
298- context.system.eventStream.publish(SemanticallyFailedModification (pmod, e))
299309 }
300310 } else {
301311 requestDownloads(progressInfo)
0 commit comments