Skip to content

Valid parameters with utf8 flag causing fatal errors #45

@The-Builder

Description

@The-Builder

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions