Skip to content

Commit

Permalink
feat: provide a more helpful error message when the specified pact fi…
Browse files Browse the repository at this point in the history
…le does not exist
  • Loading branch information
bethesque committed Apr 26, 2021
1 parent df6296e commit 29a7962
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/pact_broker/client/cli/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,26 @@ def file_list pact_files
require 'rake/file_list'

correctly_separated_pact_files = pact_files.collect{ |path| path.gsub(/\\+/, '/') }
Rake::FileList[correctly_separated_pact_files].collect do | path |
paths = Rake::FileList[correctly_separated_pact_files].collect do | path |
if File.directory?(path)
Rake::FileList[File.join(path, "*.json")]
else
path
end
end.flatten
validate_pact_path_list(paths)
end

def validate_pact_path_list(paths)
paths.collect do | path |
if File.exist?(path)
path
elsif path.start_with?("-")
raise Thor::Error.new("ERROR: pact-broker publish was called with invalid arguments #{[path]}")
else
raise Thor::Error.new("Specified pact file '#{path}' does not exist. This sometimes indicates one of the arguments has been specified with the wrong name and has been incorrectly identified as a file path.")
end
end
end

def tags
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/pact_broker/client/cli/broker_publish_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ module PactBroker::Client::CLI
end
end

context "with an invalid argument specified that gets interpreted as a path" do
let(:file_list) { ['--wrong'] }

it "raises a more helpful error" do
expect{ invoke_broker }.to raise_error(Thor::Error, 'ERROR: pact-broker publish was called with invalid arguments ["--wrong"]')
end
end

context "when a specified file does not exist" do
let(:file_list) { ['no-existy'] }

it "raises a more helpful error" do
expect{ invoke_broker }.to raise_error(Thor::Error, /Specified pact file 'no-existy' does not exist/)
end
end

context "with a tag" do
before do
subject.options = OpenStruct.new(minimum_valid_options.merge(tag: ['foo']))
Expand Down

0 comments on commit 29a7962

Please sign in to comment.