diff --git a/bin/dry-run.rb b/bin/dry-run.rb index d860960164c5..1cf3179a33a3 100755 --- a/bin/dry-run.rb +++ b/bin/dry-run.rb @@ -427,6 +427,11 @@ def handle_dependabot_error(error:) "error-type": "branch_not_found", "error-detail": { "branch-name": error.branch_name } } + when Dependabot::DirectoryNotFound + { + "error-type": "directory_not_found", + "error-detail": { "directory-name": error.directory_name } + } when Dependabot::DependencyFileNotParseable { "error-type": "dependency_file_not_parseable", diff --git a/bundler/spec/dependabot/bundler/file_fetcher_spec.rb b/bundler/spec/dependabot/bundler/file_fetcher_spec.rb index 9d8ec6cdf0e7..80e7c689112b 100644 --- a/bundler/spec/dependabot/bundler/file_fetcher_spec.rb +++ b/bundler/spec/dependabot/bundler/file_fetcher_spec.rb @@ -78,9 +78,9 @@ ) end - it "raises a DependencyFileNotFound error" do + it "raises a DirectoryNotFound error" do expect { file_fetcher_instance.files } - .to raise_error(Dependabot::DependencyFileNotFound) + .to raise_error(Dependabot::DirectoryNotFound) end end @@ -95,9 +95,9 @@ ) end - it "raises a DependencyFileNotFound error" do + it "raises a DirectoryNotFound error" do expect { file_fetcher_instance.files } - .to raise_error(Dependabot::DependencyFileNotFound) + .to raise_error(Dependabot::DirectoryNotFound) end end diff --git a/common/lib/dependabot/errors.rb b/common/lib/dependabot/errors.rb index 5328263ec970..eb2fe6ba396c 100644 --- a/common/lib/dependabot/errors.rb +++ b/common/lib/dependabot/errors.rb @@ -54,6 +54,15 @@ class NotImplemented < DependabotError; end # Repo level errors # ##################### + class DirectoryNotFound < DependabotError + attr_reader :directory_name + + def initialize(directory_name, msg = nil) + @directory_name = directory_name + super(msg) + end + end + class BranchNotFound < DependabotError attr_reader :branch_name diff --git a/common/lib/dependabot/file_fetchers/base.rb b/common/lib/dependabot/file_fetchers/base.rb index 4ed07c72e241..e5265803da3b 100644 --- a/common/lib/dependabot/file_fetchers/base.rb +++ b/common/lib/dependabot/file_fetchers/base.rb @@ -309,6 +309,8 @@ def _fetch_repo_contents(path, fetch_submodules: false, _fetch_repo_contents_fully_specified(provider, repo, tmp_path, commit) rescue *CLIENT_NOT_FOUND_ERRORS + raise Dependabot::DirectoryNotFound, directory if path == directory.gsub(%r{^/*}, "") + result = raise_errors ? -> { raise } : -> { [] } retrying ||= false diff --git a/nuget/spec/dependabot/nuget/file_fetcher_spec.rb b/nuget/spec/dependabot/nuget/file_fetcher_spec.rb index a9c899826d82..c1abea16b5fe 100644 --- a/nuget/spec/dependabot/nuget/file_fetcher_spec.rb +++ b/nuget/spec/dependabot/nuget/file_fetcher_spec.rb @@ -916,10 +916,10 @@ .to_return(status: 404) end - it "raises a Dependabot::DependencyFileNotFound error" do + it "raises a Dependabot::DirectoryNotFound error" do expect { file_fetcher_instance.files } - .to raise_error(Dependabot::DependencyFileNotFound) do |error| - expect(error.file_path).to eq("dir/.(cs|vb|fs)proj") + .to raise_error(Dependabot::DirectoryNotFound) do |error| + expect(error.directory_name).to eq("dir") end end end diff --git a/updater/lib/dependabot/file_fetcher_command.rb b/updater/lib/dependabot/file_fetcher_command.rb index 3569602a1457..a07e5e7f85b8 100644 --- a/updater/lib/dependabot/file_fetcher_command.rb +++ b/updater/lib/dependabot/file_fetcher_command.rb @@ -134,6 +134,11 @@ def handle_file_fetcher_error(error) "error-type": "branch_not_found", "error-detail": { "branch-name": error.branch_name } } + when Dependabot::DirectoryNotFound + { + "error-type": "directory_not_found", + "error-detail": { "directory-name": error.directory_name } + } when Dependabot::RepoNotFound # This happens if the repo gets removed after a job gets kicked off. # This also happens when a configured personal access token is not authz'd to fetch files from the job repo.