From a08c2392c480b04b6e159ca3ceec91048ee6758a Mon Sep 17 00:00:00 2001 From: Stephen von Takach Date: Tue, 17 Nov 2020 15:12:44 +1100 Subject: [PATCH] feat: bitfield macro outside of a bitfield error message to help simplify debugging with a less obscure error message --- shard.yml | 2 +- src/bindata.cr | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/shard.yml b/shard.yml index 0d8fca8..c48f95f 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: bindata -version: 1.8.0 +version: 1.8.1 development_dependencies: ameba: diff --git a/src/bindata.cr b/src/bindata.cr index a7f70ee..d19480f 100644 --- a/src/bindata.cr +++ b/src/bindata.cr @@ -350,7 +350,8 @@ abstract class BinData end macro bits(size, name, value = nil, default = nil) - %field = @@bit_fields["{{KLASS_NAME[0]}}_{{INDEX[0]}}"] + %field = @@bit_fields["{{KLASS_NAME[0]}}_{{INDEX[0]}}"]? + raise "#{KLASS_NAME[0]}#{ '#' }{{name}} is not defined in a bitfield. Using bitfield macro outside of a bitfield" unless %field %field.bits({{size}}, {{name.id.stringify}}) {% if size <= 8 %}