From 5f24882ef6ecc188683ce0b8957d543d015ea131 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Sat, 8 May 2021 23:15:06 +0530 Subject: [PATCH] DEV: raise plugin specific errors on failure --- plugin.rb | 5 +++-- spec/extensions/sprockets_directive_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugin.rb b/plugin.rb index 46c6fabb..1f917493 100644 --- a/plugin.rb +++ b/plugin.rb @@ -74,6 +74,7 @@ after_initialize do ../lib/custom_wizard/api/endpoint.rb ../lib/custom_wizard/api/log_entry.rb ../lib/custom_wizard/liquid_extensions/first_non_empty.rb + ../lib/custom_wizard/exceptions/exceptions.rb ../serializers/custom_wizard/api/authorization_serializer.rb ../serializers/custom_wizard/api/basic_endpoint_serializer.rb ../serializers/custom_wizard/api/endpoint_serializer.rb @@ -97,7 +98,7 @@ after_initialize do end add_to_class(::Sprockets::DirectiveProcessor, :process_require_tree_discourse_directive) do |path = "."| - raise ArgumentError, "path cannot be empty" if path == "." + raise CustomWizard::SprocketsEmptyPath, "path cannot be empty" if path == "." discourse_asset_path = "#{Rails.root}/app/assets/javascripts/" path = File.expand_path(path, discourse_asset_path) @@ -106,7 +107,7 @@ after_initialize do if stat && stat.directory? require_paths(*@environment.stat_sorted_tree_with_dependencies(path)) else - raise ArgumentError, "#{path} not found in discourse core" + raise CustomWizard::SprocketsFileNotFound, "#{path} not found in discourse core" end end diff --git a/spec/extensions/sprockets_directive_spec.rb b/spec/extensions/sprockets_directive_spec.rb index d268fd1d..5a074040 100644 --- a/spec/extensions/sprockets_directive_spec.rb +++ b/spec/extensions/sprockets_directive_spec.rb @@ -46,10 +46,10 @@ describe "Sprockets: require_tree_discourse directive" do end it "throws ArgumentError if path is empty" do - expect { @env.find_asset("require_tree_discourse_empty.js") }.to raise_error(ArgumentError).with_message("path cannot be empty") + expect { @env.find_asset("require_tree_discourse_empty.js") }.to raise_error(CustomWizard::SprocketsEmptyPath).with_message("path cannot be empty") end it "throws ArgumentError if path is non non-existent" do - expect { @env.find_asset("require_tree_discourse_non_existant.js") }.to raise_error(ArgumentError) + expect { @env.find_asset("require_tree_discourse_non_existant.js") }.to raise_error(CustomWizard::SprocketsFileNotFound) end end