From eeefb3c19a0007315d0f41ad06b4d5b4a4068115 Mon Sep 17 00:00:00 2001 From: Geod24 Date: Fri, 5 Jul 2019 17:42:00 +0900 Subject: [PATCH] Improve error messages for assertion failures Help developers realize better what they did wrong. 'Assertion failure' is the the most user-friendly message. --- source/geod24/bitblob.d | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/geod24/bitblob.d b/source/geod24/bitblob.d index 9026fb8..4c4c042 100644 --- a/source/geod24/bitblob.d +++ b/source/geod24/bitblob.d @@ -131,7 +131,12 @@ public struct BitBlob (size_t Bits) public this (scope const ubyte[] bin, bool isLE = true) { - assert(bin.length == Width); + enum W = Width; // Make sure the value is shown, not the symbol + if (bin.length != Width) + assert(0, "ubyte[] argument to " ~ typeof(this).stringof + ~ " constructor does not match the expected size of " + ~ W.stringof); + this.data[] = bin[]; if (!isLE) { @@ -161,7 +166,9 @@ public struct BitBlob (size_t Bits) public this (scope const(char)[] hexstr) { - enum ErrorMsg = "Wrong string size passed to ctor"; + enum W = Width; // Make sure the value is shown, not the symbol + enum ErrorMsg = "Length of string passed to " ~ typeof(this).stringof + ~ " constructor does not match the expected size of " ~ W.stringof; if (hexstr.length == (Width * 2) + "0x".length) { assert(hexstr[0] == '0', ErrorMsg);