diff --git a/lib/rackstash.rb b/lib/rackstash.rb index 41c4349..3aff091 100644 --- a/lib/rackstash.rb +++ b/lib/rackstash.rb @@ -10,6 +10,14 @@ require 'set' require 'rackstash/version' module Rackstash + # A custom error which is raised by methods which need to be implemented + # elsewhere, usually in a subclass. Please refer to the documentation of the + # method which raised this error for details. + # + # Note that this error is not a `StandardError` and will not be rescued + # unless it or any of its ancestors, e.g. `Exception` is specified explicitly. + class NotImplementedHereError < ScriptError; end + SEVERITIES = [ DEBUG = 0, INFO = 1, diff --git a/lib/rackstash/adapters/adapter.rb b/lib/rackstash/adapters/adapter.rb index 066e914..f8e5c1a 100644 --- a/lib/rackstash/adapters/adapter.rb +++ b/lib/rackstash/adapters/adapter.rb @@ -82,15 +82,16 @@ module Rackstash # Write a single log line to the log device. # - # This method needs to be overwritten in child classes to write the - # encoded log event to the adapter's device. By default, this method - # raises a `NotImplementedError`. + # This method needs to be overwritten in adapter sub classes to write the + # encoded log event to the adapter's device. When not overwritten, this + # method raises a {NotImplementedHereError}. # # @param log [Object] the encoded log event # @return [void] - # @raise NotImplementedError + # @raise NotImplementedHereError def write_single(log) - raise NotImplementedError, 'write needs to be implemented in a sub class' + raise NotImplementedHereError, 'write_single needs to be implemented ' + + 'in the actual adapter subclass' end private diff --git a/spec/rackstash/adapters/adapter_spec.rb b/spec/rackstash/adapters/adapter_spec.rb index fd16271..94b4c03 100644 --- a/spec/rackstash/adapters/adapter_spec.rb +++ b/spec/rackstash/adapters/adapter_spec.rb @@ -47,7 +47,8 @@ describe Rackstash::Adapters::Adapter do describe '#write_single' do it 'is not implemented in the abstract base class' do - expect { adapter.write('something') }.to raise_error(NotImplementedError) + expect { adapter.write('something') } + .to raise_error(Rackstash::NotImplementedHereError) end end end diff --git a/spec/rackstash_spec.rb b/spec/rackstash_spec.rb index a509b7c..fe91e00 100644 --- a/spec/rackstash_spec.rb +++ b/spec/rackstash_spec.rb @@ -8,6 +8,12 @@ require 'spec_helper' describe Rackstash do + describe Rackstash::NotImplementedHereError do + it 'inherits from ScriptError' do + expect(described_class.superclass).to equal ScriptError + end + end + it 'defines PROGRAME with the correct version' do expect(Rackstash::PROGNAME).to match %r{\Arackstash/v\d+(\..+)*\z} expect(Rackstash::PROGNAME).to be_frozen