diff --git a/logstash-core-event/lib/logstash/event.rb b/logstash-core-event/lib/logstash/event.rb index a297f715d..233b2e6c6 100644 --- a/logstash-core-event/lib/logstash/event.rb +++ b/logstash-core-event/lib/logstash/event.rb @@ -16,6 +16,9 @@ require "logstash/string_interpolation" class LogStash::ShutdownEvent; end class LogStash::FlushEvent; end +# Custom exceptions +class InvalidOperationException < StandardError; end + module LogStash FLUSH = LogStash::FlushEvent.new @@ -180,7 +183,7 @@ class LogStash::Event # Remove a field or field reference. Returns the value of that field when deleted def remove(fieldref) if fieldref == TIMESTAMP || fieldref == "[#{TIMESTAMP}]" - raise TypeError, "The field '@timestamp' must not be removed" + raise InvalidOperationException, "The field '@timestamp' must not be removed" end @accessors.del(fieldref) end diff --git a/logstash-core-event/spec/logstash/event_spec.rb b/logstash-core-event/spec/logstash/event_spec.rb index 12d12d654..5840e6fd0 100644 --- a/logstash-core-event/spec/logstash/event_spec.rb +++ b/logstash-core-event/spec/logstash/event_spec.rb @@ -336,7 +336,7 @@ describe LogStash::Event do context "remove" do it "should raise an exception if you attempt to remove @timestamp" do - expect{subject.remove("@timestamp")}.to raise_error(TypeError) + expect{subject.remove("@timestamp")}.to raise_error(InvalidOperationException) end end end