summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCrae <john.mccrae@progress.com>2022-05-25 05:42:32 +0000
committerGitHub <noreply@github.com>2022-05-25 05:42:32 +0000
commitaf0918e529e4706ab19e075695bd8bc014196da9 (patch)
tree789dfab843256dfe4113d3ce12b0a08a66a1635c
parentd513a441a1fc0ff89a6adf92a0fd0af2df0dbef2 (diff)
parentcb0f07953e14bc4614beb90f69ba66483fea264c (diff)
downloadchef-af0918e529e4706ab19e075695bd8bc014196da9.tar.gz
Merge pull request #11678 from chef/snehal/knife_upload_bad_error_msg
Knife upload: bad error message when a recipe has a syntax error
-rw-r--r--lib/chef/cookbook/syntax_check.rb4
-rw-r--r--spec/unit/cookbook/syntax_check_spec.rb3
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..914e2947ca 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 = ruby_file[ruby_file.index(cookbook_path.split("/").last), ruby_file.length]
+ 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..8741c89bda 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 borken/recipes/default.rb has a ruby syntax error.")
+ allow(Chef::Log).to receive(:fatal)
expect(syntax_check.validate_ruby_files).to be_falsey
end