Skip to content

Commit

Permalink
Merge pull request dependabot#6782 from dependabot/mctofu/clone-out-o…
Browse files Browse the repository at this point in the history
…f-disk

Attempt to detect OutOfDisk errors when cloning repos
  • Loading branch information
mctofu authored Mar 3, 2023
2 parents 0083751 + 348da4b commit a00c98d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
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 @@ -95,6 +95,8 @@ def clone_repo_contents
rescue Dependabot::SharedHelpers::HelperSubprocessFailed => e
if e.message.include?("fatal: Remote branch #{target_branch} not found in upstream origin")
raise Dependabot::BranchNotFound, target_branch
elsif e.message.include?("No space left on device")
raise Dependabot::OutOfDisk
end

raise Dependabot::RepoNotFound, source
Expand Down
15 changes: 15 additions & 0 deletions common/spec/dependabot/file_fetchers/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,21 @@ def fetch_files
expect(`ls #{repo_contents_path}`).to include("README")
end
end

context "when the repo exceeds available disk space" do
it "raises an out of disk error" do
allow(Dependabot::SharedHelpers).
to receive(:run_shell_command).
and_raise(
Dependabot::SharedHelpers::HelperSubprocessFailed.new(
message: "fatal: write error: No space left on device",
error_context: {}
)
)

expect { subject }.to raise_error(Dependabot::OutOfDisk)
end
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 @@ -144,6 +144,11 @@ def handle_file_fetcher_error(error)
"error-type": "dependency_file_not_found",
"error-detail": { "file-path": error.file_path }
}
when Dependabot::OutOfDisk
{
"error-type": "out_of_disk",
"error-detail": {}
}
when Dependabot::PathDependenciesNotReachable
{
"error-type": "path_dependencies_not_reachable",
Expand Down
21 changes: 21 additions & 0 deletions updater/spec/dependabot/file_fetcher_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@
expect { perform_job }.to output(/Error during file fetching; aborting/).to_stdout_from_any_process
end
end

context "when the fetcher raises a OutOfDisk error while cloning" do
before do
allow_any_instance_of(Dependabot::GoModules::FileFetcher).
to receive(:clone_repo_contents).
and_raise(Dependabot::OutOfDisk)
end

it "tells the backend about the error (and doesn't re-raise it)" do
expect(api_client).
to receive(:record_update_job_error).
with(
job_id,
error_details: {},
error_type: "out_of_disk"
)
expect(api_client).to receive(:mark_job_as_processed)

expect { perform_job }.to output(/Error during file fetching; aborting/).to_stdout_from_any_process
end
end
end

context "when the connectivity check is enabled", vcr: true do
Expand Down

0 comments on commit a00c98d

Please sign in to comment.