tidy up custom exceptions

This commit is contained in:
Adam Spiers 2014-01-29 14:21:55 +00:00
parent 7a74431e88
commit 2947139632
3 changed files with 11 additions and 6 deletions

View File

@ -1,9 +1,6 @@
require 'mixlib/shellout'
module Pacemaker
class ObjectTypeMismatch < StandardError
end
class CIBObject
attr_accessor :name, :definition
@ -68,7 +65,8 @@ module Pacemaker
@definition = self.class.get_definition(name)
if @definition and ! @definition.empty? and type != self.class.object_type
raise ObjectTypeMismatch, "Expected #{self.class.object_type} type but loaded definition was type #{type}"
raise CIBObject::TypeMismatch, \
"Expected #{self.class.object_type} type but loaded definition was type #{type}"
end
end
@ -88,4 +86,10 @@ module Pacemaker
"crm configure delete '#{name}'"
end
end
class CIBObject::DefinitionParseError < StandardError
end
class CIBObject::TypeMismatch < StandardError
end
end

View File

@ -26,7 +26,8 @@ class Pacemaker::Resource::Primitive < Pacemaker::Resource
def parse_definition
unless definition =~ /\Aprimitive (\S+) (\S+)/
raise RuntimeError, "Couldn't parse definition '#{definition}'"
raise Pacemaker::CIBObject::DefinitionParseError, \
"Couldn't parse definition '#{definition}'"
end
self.name = $1
self.agent = $2

View File

@ -14,7 +14,7 @@ describe Pacemaker::Resource::Primitive do
.to receive(:stdout) \
.and_return("clone foo blah blah")
expect { @primitive.load_definition }.to \
raise_error(Pacemaker::ObjectTypeMismatch,
raise_error(Pacemaker::CIBObject::TypeMismatch,
"Expected primitive type but loaded definition was type clone")
end