From 03fbc66197b10699352ed6dd397558d4d4749464 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Fri, 9 Oct 2020 14:55:57 +0300 Subject: [PATCH] performance optimization: avoid stack trace collection for RecoverableModifierError --- src/main/scala/scorex/core/validation/ModifierError.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/scala/scorex/core/validation/ModifierError.scala b/src/main/scala/scorex/core/validation/ModifierError.scala index 8811c0583..24c58ea81 100644 --- a/src/main/scala/scorex/core/validation/ModifierError.scala +++ b/src/main/scala/scorex/core/validation/ModifierError.scala @@ -1,5 +1,7 @@ package scorex.core.validation +import scala.util.control.NoStackTrace + /** Base trait for errors that were occurred during NodeView Modifier validation */ trait ModifierError { @@ -22,11 +24,12 @@ class MalformedModifierError(val message: String, cause: Option[Throwable] = Non def toThrowable: Throwable = this } -/** Temporary modifier error that may be recovered in future after some history updates +/** Temporary modifier error that may be recovered in future after some history updates. + * When an instance is created, the stack trace is not collected which makes this exception lightweight. */ @SuppressWarnings(Array("org.wartremover.warts.Null")) class RecoverableModifierError(val message: String, cause: Option[Throwable] = None) - extends Exception(message, cause.orNull) with ModifierError { + extends Exception(message, cause.orNull) with ModifierError with NoStackTrace { def isFatal: Boolean = false def toThrowable: Throwable = this }