From cab9d1c972d07ac1295f6cb8e555d07212740cca Mon Sep 17 00:00:00 2001 From: Liam Dawson Date: Sat, 31 Oct 2015 22:44:19 +1000 Subject: [PATCH 1/6] Subclass errors from a general Lotus module error --- lib/lotus/view/rendering/layout_registry.rb | 3 ++- lib/lotus/view/view_error.rb | 16 ++++++++++++++++ test/layout_test.rb | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 lib/lotus/view/view_error.rb diff --git a/lib/lotus/view/rendering/layout_registry.rb b/lib/lotus/view/rendering/layout_registry.rb index 1efbbefc..5b3aa767 100644 --- a/lib/lotus/view/rendering/layout_registry.rb +++ b/lib/lotus/view/rendering/layout_registry.rb @@ -1,5 +1,6 @@ require 'lotus/view/rendering/null_template' require 'lotus/view/rendering/templates_finder' +require 'lotus/view/view_error' module Lotus module View @@ -9,7 +10,7 @@ module Rendering # This is raised at the runtime when Lotus::Layout cannot find it's template. # # @since 0.3.0 - class MissingTemplateLayoutError < ::StandardError + class MissingTemplateLayoutError < Lotus::View::ViewError def initialize(template) super("Can't find layout template '#{ template }'") end diff --git a/lib/lotus/view/view_error.rb b/lib/lotus/view/view_error.rb new file mode 100644 index 00000000..df4fc05b --- /dev/null +++ b/lib/lotus/view/view_error.rb @@ -0,0 +1,16 @@ +# Base view error +# +# This is a base error used to produce Lotus view errors. +# +# Allows better rescue options than simply catching `StandardError`. +# +# @since 0.4.4 +module Lotus + module View + class ViewError < ::StandardError + def intialize(message) + super(message) + end + end + end +end diff --git a/test/layout_test.rb b/test/layout_test.rb index 0f9ad9bb..3d48637b 100644 --- a/test/layout_test.rb +++ b/test/layout_test.rb @@ -8,7 +8,7 @@ end end - it "raise error if template isn't found" do + it "raise subclassed error if template isn't found" do Lotus::View.unload! class MissingLayout @@ -19,6 +19,7 @@ class MissingLayout Lotus::View.load! }.must_raise(Lotus::View::Rendering::MissingTemplateLayoutError) error.message.must_include "Can't find layout template 'MissingLayout'" + error.class.ancestors.must_include Lotus::View::ViewError end it 'concrete methods are available in layout template' do From 6ae1ba1760b477948a6c4e5d9d058a1933791e15 Mon Sep 17 00:00:00 2001 From: Liam Dawson Date: Mon, 2 Nov 2015 22:18:53 +1000 Subject: [PATCH 2/6] Change ViewError to Error --- lib/lotus/view/view_error.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/lotus/view/view_error.rb b/lib/lotus/view/view_error.rb index df4fc05b..de8bcc67 100644 --- a/lib/lotus/view/view_error.rb +++ b/lib/lotus/view/view_error.rb @@ -7,10 +7,7 @@ # @since 0.4.4 module Lotus module View - class ViewError < ::StandardError - def intialize(message) - super(message) - end + class Error < ::StandardError end end end From cfbc34e8f61f591e844870380eb4a01bf2b821d9 Mon Sep 17 00:00:00 2001 From: Liam Dawson Date: Mon, 2 Nov 2015 22:19:22 +1000 Subject: [PATCH 3/6] Change template error test to use new class --- test/layout_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/layout_test.rb b/test/layout_test.rb index 3d48637b..b125862f 100644 --- a/test/layout_test.rb +++ b/test/layout_test.rb @@ -19,7 +19,7 @@ class MissingLayout Lotus::View.load! }.must_raise(Lotus::View::Rendering::MissingTemplateLayoutError) error.message.must_include "Can't find layout template 'MissingLayout'" - error.class.ancestors.must_include Lotus::View::ViewError + error.class.ancestors.must_include Lotus::View::Error end it 'concrete methods are available in layout template' do From d7b43647487d2db6c978da72cf32add2f273e519 Mon Sep 17 00:00:00 2001 From: Liam Dawson Date: Mon, 2 Nov 2015 22:19:47 +1000 Subject: [PATCH 4/6] Rename view_error.rb to error.rb --- lib/lotus/view/{view_error.rb => error.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/lotus/view/{view_error.rb => error.rb} (100%) diff --git a/lib/lotus/view/view_error.rb b/lib/lotus/view/error.rb similarity index 100% rename from lib/lotus/view/view_error.rb rename to lib/lotus/view/error.rb From 1f8431bd441f5e54649226d99afe6eb64ff2e1cc Mon Sep 17 00:00:00 2001 From: Liam Dawson Date: Mon, 2 Nov 2015 22:21:27 +1000 Subject: [PATCH 5/6] Inherit MissingTemplateLayoutError from View::Error --- lib/lotus/view/rendering/layout_registry.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lotus/view/rendering/layout_registry.rb b/lib/lotus/view/rendering/layout_registry.rb index 5b3aa767..a278f446 100644 --- a/lib/lotus/view/rendering/layout_registry.rb +++ b/lib/lotus/view/rendering/layout_registry.rb @@ -10,7 +10,7 @@ module Rendering # This is raised at the runtime when Lotus::Layout cannot find it's template. # # @since 0.3.0 - class MissingTemplateLayoutError < Lotus::View::ViewError + class MissingTemplateLayoutError < Lotus::View::Error def initialize(template) super("Can't find layout template '#{ template }'") end From e9eb2b921d131fabcabd32479ffc322fd2c6e1fc Mon Sep 17 00:00:00 2001 From: Liam Dawson Date: Mon, 2 Nov 2015 22:22:54 +1000 Subject: [PATCH 6/6] Include view/error instead of view/view_error --- lib/lotus/view/rendering/layout_registry.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lotus/view/rendering/layout_registry.rb b/lib/lotus/view/rendering/layout_registry.rb index a278f446..ccdccd47 100644 --- a/lib/lotus/view/rendering/layout_registry.rb +++ b/lib/lotus/view/rendering/layout_registry.rb @@ -1,6 +1,6 @@ require 'lotus/view/rendering/null_template' require 'lotus/view/rendering/templates_finder' -require 'lotus/view/view_error' +require 'lotus/view/error' module Lotus module View