Skip to content

Commit

Permalink
registry error error handler correction (#10618)
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-sandhu authored Sep 17, 2024
1 parent 99fc141 commit a602925
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
19 changes: 19 additions & 0 deletions common/lib/dependabot/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ def self.updater_error_details(error)
"error-type": "illformed_requirement",
"error-detail": { message: error.message }
}
when RegistryError
{
"error-type": "registry_error",
"error-detail": { status: error.status,
msg: error.message }
}
when
IncompatibleCPU,
NetworkUnsafeHTTP
Expand Down Expand Up @@ -612,6 +618,19 @@ def initialize(source)
end
end

class RegistryError < DependabotError
extend T::Sig

sig { returns(Integer) }
attr_reader :status

sig { params(status: Integer, msg: String).void }
def initialize(status, msg)
@status = status
super(msg)
end
end

# Useful for JS file updaters, where the registry API sometimes returns
# different results to the actual update process
class InconsistentRegistryResponse < DependabotError; end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ class UpdateChecker
class LatestVersionFinder
extend T::Sig

class RegistryError < StandardError
attr_reader :status

def initialize(status, msg)
@status = status
super(msg)
end
end

def initialize(dependency:, credentials:, dependency_files:,
ignored_versions:, security_advisories:,
raise_on_ignored: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@

it "raises an error" do
expect { version_finder.latest_version_from_registry }
.to raise_error(described_class::RegistryError)
.to raise_error(Dependabot::RegistryError)
end
end

Expand Down Expand Up @@ -777,7 +777,7 @@
it "raises an error" do
expect { version_finder.latest_version_from_registry }
.to raise_error do |err|
expect(err.class).to eq(described_class::RegistryError)
expect(err.class).to eq(Dependabot::RegistryError)
expect(err.status).to eq(404)
end
end
Expand Down Expand Up @@ -844,7 +844,7 @@

it "raises an error" do
expect { version_finder.latest_version_from_registry }
.to raise_error(described_class::RegistryError)
.to raise_error(Dependabot::RegistryError)
end
end
end
Expand Down Expand Up @@ -909,7 +909,7 @@
it "raises an error" do
expect { version_finder.latest_version_from_registry }
.to raise_error do |err|
expect(err.class).to eq(described_class::RegistryError)
expect(err.class).to eq(Dependabot::RegistryError)
expect(err.status).to eq(404)
end
end
Expand Down

0 comments on commit a602925

Please sign in to comment.