@@ -37,8 +37,9 @@ _PyZstd_set_c_parameters(ZstdCompressor *self, PyObject *level_or_options,
3737 if (PyLong_Check (level_or_options )) {
3838 const int level = PyLong_AsInt (level_or_options );
3939 if (level == -1 && PyErr_Occurred ()) {
40- PyErr_SetString (PyExc_ValueError ,
41- "Compression level should be 32-bit signed int value." );
40+ PyErr_Format (PyExc_ValueError ,
41+ "Compression level should be an int value between %d and %d." ,
42+ ZSTD_minCLevel (), ZSTD_maxCLevel ());
4243 return -1 ;
4344 }
4445
@@ -72,18 +73,19 @@ _PyZstd_set_c_parameters(ZstdCompressor *self, PyObject *level_or_options,
7273 return -1 ;
7374 }
7475
75- /* Both key & value should be 32-bit signed int */
7676 const int key_v = PyLong_AsInt (key );
7777 if (key_v == -1 && PyErr_Occurred ()) {
7878 PyErr_SetString (PyExc_ValueError ,
79- "Key of option dict should be 32-bit signed int value ." );
79+ "Key of options dict should be a CParameter attribute ." );
8080 return -1 ;
8181 }
8282
83+ // TODO(emmatyping): check bounds when there is a value error here for better
84+ // error message?
8385 const int value_v = PyLong_AsInt (value );
8486 if (value_v == -1 && PyErr_Occurred ()) {
8587 PyErr_SetString (PyExc_ValueError ,
86- "Value of option dict should be 32-bit signed int value ." );
88+ "Value of option dict should be an int." );
8789 return -1 ;
8890 }
8991
0 commit comments