Bug report
Bug description:
I registered the error handler returning a wrong value to codecs.register_error(), then using it with str.encode() gets the less clear error message as shown below:
import codecs
def my_error_handler(s):
return ("ok",)
codecs.register_error('original_handler', my_error_handler)
v = 'pythön!'
print(v.encode(encoding='ascii', errors='original_handler'))
# TypeError: encoding error handler must return (str/bytes, int) tuple
So, the error message should be clearer like below:
TypeError: encoding error handler must return a tuple of two elements (str/bytes, int)
CPython versions tested on:
3.13
Operating systems tested on:
Windows