Skip to content

Commit

Permalink
(PDK-1363) Update error messages
Browse files Browse the repository at this point in the history
This commit updates the error messages to be more descriptive of what caused the
error.
  • Loading branch information
glennsarti committed Nov 27, 2019
1 parent ff93d12 commit 4ffd580
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/pdk/module/template_dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ module TemplateDir
# @api public
def self.with(uri, module_metadata = {}, init = false)
unless block_given?
raise ArgumentError, _('%{class_name} must be initialized with a block.') % { class_name: self.class.name }
raise ArgumentError, _('%{class_name}.with must be passed a block.') % { class_name: name }
end
unless uri.is_a? PDK::Util::TemplateURI
raise ArgumentError, _('PDK::Module::TemplateDir.for must be initialized with a PDK::Util::TemplateURI, got a %{uri_type}') % { uri_type: uri.class }
raise ArgumentError, _('%{class_name}.with must be passed a PDK::Util::TemplateURI, got a %{uri_type}') % { uri_type: uri.class, class_name: name }
end

if PDK::Util::Git.repo?(uri.bare_uri)
Expand Down
2 changes: 1 addition & 1 deletion lib/pdk/module/template_dir/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def initialize(uri, module_metadata = {}, init = false)
raise ArgumentError, _('%{class_name} must be initialized with a block.') % { class_name: self.class.name }
end
unless uri.is_a? PDK::Util::TemplateURI
raise ArgumentError, _('PDK::Module::TemplateDir::Base.new must be initialized with a PDK::Util::TemplateURI, got a %{uri_type}') % { uri_type: uri.class }
raise ArgumentError, _('%{class_name} must be initialized with a PDK::Util::TemplateURI, got a %{uri_type}') % { uri_type: uri.class, class_name: self.class.name }
end

@path, @is_temporary_path = template_path(uri)
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/pdk/module/template_dir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
it 'raises an ArgumentError' do
expect {
described_class.with(uri, module_metadata)
}.to raise_error(ArgumentError, %r{must be initialized with a block}i)
}.to raise_error(ArgumentError, %r{must be passed a block}i)
end
end

context 'when not initialized with a PDK::Util::TemplateURI' do
it 'raises an ArgumentError' do
expect {
described_class.with(path_or_url, module_metadata) {}
}.to raise_error(ArgumentError, %r{must be initialized with a PDK::Util::TemplateURI}i)
}.to raise_error(ArgumentError, %r{must be passed a PDK::Util::TemplateURI}i)
end
end

Expand Down

0 comments on commit 4ffd580

Please sign in to comment.