diff options
author | snehaldwivedi <sdwivedi@msystechnologies.com> | 2021-06-09 05:52:18 -0700 |
---|---|---|
committer | Marc A. Paradise <marc.paradise@gmail.com> | 2022-05-24 15:25:14 -0400 |
commit | f859ba08cc51f79d34928316d50df8a9b8f7af1f (patch) | |
tree | 64c1ed6917bde550b124e9456c03cafb23bcf73a | |
parent | a5e6b4e47c82fc9e741192006b98d0dec237c1fe (diff) | |
download | chef-f859ba08cc51f79d34928316d50df8a9b8f7af1f.tar.gz |
Knife upload: bad error message when a recipe has a syntax error
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
-rw-r--r-- | lib/chef/cookbook/syntax_check.rb | 4 | ||||
-rw-r--r-- | spec/unit/cookbook/syntax_check_spec.rb | 3 |
2 files changed, 5 insertions, 2 deletions
diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb index 555d2f6715..d94b7ed074 100644 --- a/lib/chef/cookbook/syntax_check.rb +++ b/lib/chef/cookbook/syntax_check.rb @@ -248,8 +248,8 @@ class Chef # Debugs ruby syntax errors by printing the path to the file and any # diagnostic info given in +error_message+ def invalid_ruby_file(ruby_file, error_message) - file_relative_path = ruby_file[/^#{Regexp.escape(cookbook_path + File::Separator)}(.*)/, 1] - Chef::Log.fatal("Cookbook file #{file_relative_path} has a ruby syntax error:") + file_relative_path = File.basename(ruby_file) + Chef::Log.fatal("Cookbook file #{file_relative_path} has a ruby syntax error.") error_message.each_line { |l| Chef::Log.fatal(l.chomp) } false end diff --git a/spec/unit/cookbook/syntax_check_spec.rb b/spec/unit/cookbook/syntax_check_spec.rb index f9e7bc0d25..88f0f102a7 100644 --- a/spec/unit/cookbook/syntax_check_spec.rb +++ b/spec/unit/cookbook/syntax_check_spec.rb @@ -159,12 +159,15 @@ describe Chef::Cookbook::SyntaxCheck do end describe "and a file has a syntax error" do + before do cookbook_path = File.join(CHEF_SPEC_DATA, "cookbooks", "borken") syntax_check.cookbook_path.replace(cookbook_path) end it "it indicates that a ruby file has a syntax error" do + expect(Chef::Log).to receive(:fatal).with("Cookbook file default.rb has a ruby syntax error.") + allow(Chef::Log).to receive(:fatal) expect(syntax_check.validate_ruby_files).to be_falsey end |