Skip to content

Commit 1be1e1a

Browse files
committed
print the invalid tag text on regex failure
1 parent e0ba686 commit 1be1e1a

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/main.zig

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -980,13 +980,15 @@ pub const Context = struct {
980980
if (!(is_at_start and is_at_end)) {
981981
options.setError(.{ .invalid_tag_name = .{
982982
.full_regex = self.library_config.tag_name_regex_string.?,
983+
.text = text,
983984
.matched_result = text[capture.start..capture.end],
984985
} });
985986
return error.InvalidTagName;
986987
}
987988
} else {
988989
options.setError(.{ .invalid_tag_name = .{
989990
.full_regex = self.library_config.tag_name_regex_string.?,
991+
.text = text,
990992
.matched_result = null,
991993
} });
992994
return error.InvalidTagName;
@@ -998,6 +1000,7 @@ pub const Context = struct {
9981000
none: void,
9991001
invalid_tag_name: struct {
10001002
full_regex: []const u8,
1003+
text: []const u8,
10011004
matched_result: ?[]const u8 = null,
10021005
},
10031006

@@ -1010,18 +1013,11 @@ pub const Context = struct {
10101013
_ = f;
10111014
_ = options;
10121015
return switch (self) {
1013-
.invalid_tag_name => |data| if (data.matched_result) |matched|
1014-
std.fmt.format(
1015-
writer,
1016-
"regex {s} does not match to given tag name, only '{?s}'",
1017-
.{ data.full_regex, matched },
1018-
)
1019-
else
1020-
std.fmt.format(
1021-
writer,
1022-
"regex {s} does not match to given tag name",
1023-
.{data.full_regex},
1024-
),
1016+
.invalid_tag_name => |data| std.fmt.format(
1017+
writer,
1018+
"regex {s} does not match to given tag name, got '{s}', matched {?s}",
1019+
.{ data.full_regex, data.text, data.matched_result },
1020+
),
10251021
.none => {},
10261022
};
10271023
}

0 commit comments

Comments
 (0)