Properly raise an exception when the consumer is given an empty topic

This commit is contained in:
R. Tyler Croy 2014-08-30 13:36:48 -07:00
parent 655cc4463a
commit 0eb18479b6
2 changed files with 10 additions and 3 deletions

View File

@ -378,9 +378,11 @@ static VALUE consumer_consume(VALUE self) {
Data_Get_Struct(self, HermannInstanceConfig, consumerConfig);
if (consumerConfig->topic==NULL) {
fprintf(stderr, "Topic is null!");
return;
if ((NULL == consumerConfig->topic) ||
(0 == strlen(consumerConfig->topic))) {
fprintf(stderr, "Topic is null!\n");
rb_raise(rb_eRuntimeError, "Topic cannot be empty");
return self;
}
if (!consumerConfig->isInitialized) {

View File

@ -26,5 +26,10 @@ describe Hermann::Consumer do
let(:brokers) { '' }
it_behaves_like 'an error condition'
end
context 'with a bad topic' do
let(:topic) { '' }
it_behaves_like 'an error condition'
end
end
end