From ad664d9f934b879b393092497492eac526b52254 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Wed, 14 Aug 2024 11:24:25 -0300 Subject: [PATCH] Added error handling --- src/bytes_regex.cr | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bytes_regex.cr b/src/bytes_regex.cr index 737ac62..72b1151 100644 --- a/src/bytes_regex.cr +++ b/src/bytes_regex.cr @@ -16,8 +16,11 @@ module BytesRegex out erroroffset, nil) else - # FIXME: show actual error message - raise Exception.new "Error compiling regex" + msg = String.new(256) do |buffer| + bytesize = LibPCRE2.get_error_message(errorcode, buffer, 256) + {bytesize, 0} + end + raise Exception.new "Error #{msg} compiling regex at offset #{erroroffset}" end end @@ -37,7 +40,7 @@ module BytesRegex match_data, nil) if rc < 0 - # FIXME: handle actual errors + # No match, do nothing else ovector = LibPCRE2.get_ovector_pointer(match_data) (0...rc).each do |i|