From 930b8a9f3cb3aff8985dff0d0453e29e66ec0527 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Sat, 31 Oct 2020 00:15:31 +0300 Subject: [PATCH] Result cleanup GitOrigin-RevId: 4c3146734479e6abc155fd901b65bd8c93d2d0c3 --- python/openapi/src/com/jetbrains/python/Result.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/openapi/src/com/jetbrains/python/Result.kt b/python/openapi/src/com/jetbrains/python/Result.kt index 499707801623..6f1453cba629 100644 --- a/python/openapi/src/com/jetbrains/python/Result.kt +++ b/python/openapi/src/com/jetbrains/python/Result.kt @@ -21,7 +21,10 @@ sealed class Result { } val successOrNull: SUCC? get() = if (this is Success) result else null - fun successOr(@NonNls errorForLog: String): SUCC { - return (this as? Success)?.result ?: throw AssertionError(errorForLog) + fun orThrow(onError: (ERR) -> Throwable = { e -> AssertionError(e) }): SUCC { + when (this) { + is Success -> return result + is Failure -> throw onError(this.error) + } } } \ No newline at end of file