How to stop logstash when ruby filter encountered error

If you actually want to exit the logstash process then see here. If you want to drop the events when you get an error you can call event.cancel in the ruby filter.