-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Several methods (e. g. connection, fetch) return an unspecific error when being fed strings with the utf8 flag set.
Configurations are often read from yaml files and these, as any other parameters may be flagged 'utf8' although the string is plain ascii.
Reproduce:
use Kafka::Connection;
my $h = 'localhost';
setting the utf8 flag generates the error
utf8::upgrade($h);
print utf8::is_utf8($h) ? "isUtf8\n" : "isNOTUtf8\n";
Kafka::Connection->new(host => $h);
exit;
Output without the flag
~/temp$ ./test.pl
isNOTUtf8
Output with the flag being set
~/temp$ ./test.pl
isUtf8
Invalid argument: host
Trace begun at /opt/perl-5.12.3/lib/site_perl/5.12.3/Kafka/Connection.pm
line 1592 Kafka::Connection::_error('Kafka::Connection=HASH(0x2536cf0)',
-1000, 'host') called at
/opt/perl-5.12.3/lib/site_perl/5.12.3/Kafka/Connection.pm line 447
Kafka::Connection::new('Kafka::Connection', 'host', 'localhost') called at
test.pl line 28
Workaround:
Use utf8::downgrade() on the parameters before passing to the Kafka methods.
Ikegami strongly discourages from using is_utf8() anywhere but debugging/developing.
https://stackoverflow.com/questions/14579560/am-i-using-utf8is-utf8-correctly
Here Kafka should probably leave the parameter error handling to e.g. the network layer.
Also, error messages should be more explicit, telling the user exactly what went wrong.
Thanks to @eserte who helped me with debugging this case.