From 7acb7a5b8fa374ee2b68c28c2e438cb6c9265e58 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Wed, 5 Jul 2023 16:52:28 +0800 Subject: [PATCH] Fsdk/Misc: add better assert function Debug.Assert is better than failwith in the sense that its failure cannot be captured by a try-with block, however failwith is better than Debug.Assert because it also fails in !DEBUG (fail fast is better). So here we create the best of both worlds. --- Fsdk/Misc.fs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Fsdk/Misc.fs b/Fsdk/Misc.fs index 0aed3cd9..79e9f0f8 100644 --- a/Fsdk/Misc.fs +++ b/Fsdk/Misc.fs @@ -4,6 +4,7 @@ open System open System.IO open System.Text open System.Reflection +open System.Diagnostics open System.Linq #if LEGACY_FRAMEWORK @@ -900,3 +901,9 @@ module Misc = let ExtractEmbeddedResourceFileContents(resourceName: string) = let assembly = Assembly.GetCallingAssembly() ExtractEmbeddedResourceFileContentsFromAssembly resourceName assembly + + let BetterAssert (expr: bool) (errMsg: string) = + Debug.Assert(expr, errMsg) + + if not expr then + failwith errMsg