Skip to content

Commit cff9c9b

Browse files
committed
Reuse error message
1 parent cf3bb7e commit cff9c9b

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

shared-bindings/_pixelbuf/PixelBuf.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,8 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a
108108
char *b = strchr(byteorder, 'B');
109109
char *w = strchr(byteorder, 'W');
110110
int num_chars = (dotstar ? 1 : 0) + (w ? 1 : 0) + (r ? 1 : 0) + (g ? 1 : 0) + (b ? 1 : 0);
111-
if (num_chars < byteorder_details.bpp)
112-
mp_raise_ValueError(translate("Unexpected character in byteorder"));
113-
if (!(r && b && g))
114-
mp_raise_ValueError(translate("Incomplete byteorder string"));
111+
if ((num_chars < byteorder_details.bpp) || !(r && b && g))
112+
mp_raise_ValueError(translate("Invalid byteorder string"));
115113
byteorder_details.is_dotstar = dotstar ? true : false;
116114
byteorder_details.has_white = w ? true : false;
117115
byteorder_details.byteorder.r = r - byteorder;
@@ -124,16 +122,16 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a
124122
// if 'D' is elsewhere, error out
125123
if (dotstar) {
126124
size_t dotstar_pos = dotstar - byteorder;
127-
if (dotstar_pos == 4) {
125+
if (dotstar_pos == 3) {
128126
byteorder_details.byteorder.b += 1;
129127
byteorder_details.byteorder.g += 1;
130128
byteorder_details.byteorder.r += 1;
131129
} else if (dotstar_pos != 0) {
132-
mp_raise_ValueError(translate("Dotstar position invalid"));
130+
mp_raise_ValueError(translate("Invalid byteorder string"));
133131
}
134132
}
135133
if (byteorder_details.has_white && byteorder_details.is_dotstar)
136-
mp_raise_ValueError(translate("Can not use dotstar with a white byte"));
134+
mp_raise_ValueError(translate("Invalid byteorder string"));
137135

138136
size_t effective_bpp = byteorder_details.is_dotstar ? 4 : byteorder_details.bpp; // Always 4 for DotStar
139137
size_t bytes = args[ARG_size].u_int * effective_bpp;

0 commit comments

Comments
 (0)