Skip to content

Commit eeefb3c

Browse files
committed
Improve error messages for assertion failures
Help developers realize better what they did wrong. 'Assertion failure' is the the most user-friendly message.
1 parent e3dd483 commit eeefb3c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

source/geod24/bitblob.d

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ public struct BitBlob (size_t Bits)
131131

132132
public this (scope const ubyte[] bin, bool isLE = true)
133133
{
134-
assert(bin.length == Width);
134+
enum W = Width; // Make sure the value is shown, not the symbol
135+
if (bin.length != Width)
136+
assert(0, "ubyte[] argument to " ~ typeof(this).stringof
137+
~ " constructor does not match the expected size of "
138+
~ W.stringof);
139+
135140
this.data[] = bin[];
136141
if (!isLE)
137142
{
@@ -161,7 +166,9 @@ public struct BitBlob (size_t Bits)
161166

162167
public this (scope const(char)[] hexstr)
163168
{
164-
enum ErrorMsg = "Wrong string size passed to ctor";
169+
enum W = Width; // Make sure the value is shown, not the symbol
170+
enum ErrorMsg = "Length of string passed to " ~ typeof(this).stringof
171+
~ " constructor does not match the expected size of " ~ W.stringof;
165172
if (hexstr.length == (Width * 2) + "0x".length)
166173
{
167174
assert(hexstr[0] == '0', ErrorMsg);

0 commit comments

Comments
 (0)