Introduced InvalidOperationException

Fixes #4425
This commit is contained in:
Lucas Bremgartner 2016-02-05 14:55:32 +01:00 committed by Suyog Rao
parent e023bd4bc6
commit 6bf6e38f59
2 changed files with 5 additions and 2 deletions

View file

@ -16,6 +16,9 @@ require "logstash/string_interpolation"
class LogStash::ShutdownEvent; end class LogStash::ShutdownEvent; end
class LogStash::FlushEvent; end class LogStash::FlushEvent; end
# Custom exceptions
class InvalidOperationException < StandardError; end
module LogStash module LogStash
FLUSH = LogStash::FlushEvent.new 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 # Remove a field or field reference. Returns the value of that field when deleted
def remove(fieldref) def remove(fieldref)
if fieldref == TIMESTAMP || fieldref == "[#{TIMESTAMP}]" if fieldref == TIMESTAMP || fieldref == "[#{TIMESTAMP}]"
raise TypeError, "The field '@timestamp' must not be removed" raise InvalidOperationException, "The field '@timestamp' must not be removed"
end end
@accessors.del(fieldref) @accessors.del(fieldref)
end end

View file

@ -336,7 +336,7 @@ describe LogStash::Event do
context "remove" do context "remove" do
it "should raise an exception if you attempt to remove @timestamp" 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 end
end end