Skip to content

Commit

Permalink
Expose a new directory_not_found user error
Browse files Browse the repository at this point in the history
If the user is configuring a directory for dependabot that no longer
exists, and the ecosystem does not clone full repositories, we'll end up
with unknown `Octokit::NotFound` errors when trying to fetch dependency
files.

This commits creates a new user that will be displayed to the user so
that she can fix her configuration.
  • Loading branch information
deivid-rodriguez committed Oct 12, 2023
1 parent 64b11c4 commit 7cb1b1e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
5 changes: 5 additions & 0 deletions bin/dry-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions bundler/spec/dependabot/bundler/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
9 changes: 9 additions & 0 deletions common/lib/dependabot/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions common/lib/dependabot/file_fetchers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions nuget/spec/dependabot/nuget/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/<anything>.(cs|vb|fs)proj")
.to raise_error(Dependabot::DirectoryNotFound) do |error|
expect(error.directory_name).to eq("dir")
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions updater/lib/dependabot/file_fetcher_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7cb1b1e

Please sign in to comment.