Skip to content

Commit

Permalink
Metadata fetching: Handle ENOENT when git not installed (#6409)
Browse files Browse the repository at this point in the history
This git fallback is being hit whenever there's a non-`200` response
code. However, if `git` isn't installed, this will result in throwing:
```shell
Errno::ENOENT with No such file or directory - git
```

So catch the error and handle it.
  • Loading branch information
jeffwidman authored Jul 25, 2023
1 parent 3447b11 commit 015fb77
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions common/lib/dependabot/git_metadata_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@ def fetch_raw_upload_pack_with_git_for(uri)
command = "git ls-remote #{service_pack_uri}"
command = SharedHelpers.escape_command(command)

stdout, stderr, process = Open3.capture3(env, command)
# package the command response like a HTTP response so error handling
# remains unchanged
if process.success?
OpenStruct.new(body: stdout, status: 200)
begin
stdout, stderr, process = Open3.capture3(env, command)
# package the command response like a HTTP response so error handling remains unchanged
rescue Errno::ENOENT => e # thrown when `git` isn't installed...
OpenStruct.new(body: e.message, status: 500)
else
OpenStruct.new(body: stderr, status: 500)
if process.success?
OpenStruct.new(body: stdout, status: 200)
else
OpenStruct.new(body: stderr, status: 500)
end
end
end

Expand Down

0 comments on commit 015fb77

Please sign in to comment.