Skip to content

Commit

Permalink
Handle DependencyFileNotParseable error on Updater.run (dependabot#11288
Browse files Browse the repository at this point in the history
)

* Handle DependencyFileNotParseable error on Updater.run

* Stop handling standard error

* Fix failing CI checks

* Count error as stdout

* Remove rescued exception from stdout test
  • Loading branch information
amazimbe authored Jan 16, 2025
1 parent 47316b7 commit 43e0298
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
10 changes: 10 additions & 0 deletions common/lib/dependabot/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def self.parser_error_details(error)

# rubocop:disable Lint/RedundantCopDisableDirective
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/AbcSize
sig { params(error: StandardError).returns(T.nilable(T::Hash[Symbol, T.untyped])) }
def self.updater_error_details(error)
case error
Expand All @@ -179,6 +180,14 @@ def self.updater_error_details(error)
"error-type": "dependency_file_not_evaluatable",
"error-detail": { message: error.message }
}
when Dependabot::DependencyFileNotParseable
{
"error-type": "dependency_file_not_parseable",
"error-detail": {
message: error.message,
"file-path": error.file_path
}
}
when Dependabot::GitDependenciesNotReachable
{
"error-type": "git_dependencies_not_reachable",
Expand Down Expand Up @@ -294,6 +303,7 @@ def self.updater_error_details(error)
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Lint/RedundantCopDisableDirective
# rubocop:enable Metrics/AbcSize

class DependabotError < StandardError
extend T::Sig
Expand Down
1 change: 0 additions & 1 deletion silent/tests/testdata/vu-group-semver-error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

! dependabot update -f input.yml --local . --updater-image ghcr.io/dependabot/dependabot-updater-silent
# If this appears in the logs twice that means it tried to create a PR again
stderr -count=1 DependencyFileNotParseable
stdout -count=2 create_pull_request
pr-created expected-group.json
pr-created expected-individual.json
Expand Down
30 changes: 25 additions & 5 deletions updater/lib/dependabot/update_files_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ def perform_job
#
# As above, we can remove the responsibility for handling fatal/job halting
# errors from Dependabot::Updater entirely.
Dependabot::Updater.new(
service: service,
job: job,
dependency_snapshot: dependency_snapshot
).run
begin
Dependabot::Updater.new(
service: service,
job: job,
dependency_snapshot: dependency_snapshot
).run
rescue Dependabot::DependencyFileNotParseable => e
handle_dependency_file_not_parseable_error(e)
return service.mark_job_as_processed(Environment.job_definition["base_commit_sha"])
end

# Wait for all PRs to be created
service.wait_for_calls_to_finish
Expand Down Expand Up @@ -129,5 +134,20 @@ def handle_parser_error(error)
)
end
# rubocop:enable Metrics/AbcSize, Layout/LineLength, Metrics/MethodLength

def handle_dependency_file_not_parseable_error(error)
error_details = Dependabot.updater_error_details(error)

service.record_update_job_error(
error_type: T.must(error_details).fetch(:"error-type"),
error_details: T.must(error_details)[:"error-detail"]
)
return unless Experiments.enabled?(:record_update_job_unknown_error)

service.record_update_job_unknown_error(
error_type: T.must(error_details).fetch(:"error-type"),
error_details: T.must(error_details)[:"error-detail"]
)
end
end
end
32 changes: 32 additions & 0 deletions updater/spec/dependabot/update_files_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,38 @@
end
end

context "with a Dependabot::DependencyFileNotParseable error" do
let(:error) { Dependabot::DependencyFileNotParseable.new("path/to/file", "a") }

let(:snapshot) do
instance_double(Dependabot::DependencySnapshot,
base_commit_sha: "1c6331732c41e4557a16dacb82534f1d1c831848")
end

let(:updater) do
instance_double(Dependabot::Updater,
service: service,
job: job,
dependency_snapshot: snapshot)
end

before do
allow(Dependabot::DependencySnapshot).to receive(:create_from_job_definition).and_return(snapshot)
allow(Dependabot::Updater).to receive(:new).and_return(updater)
allow(updater).to receive(:run).and_raise(error)
end

it "only records a job error" do
expect(service).not_to receive(:capture_exception)
expect(service).to receive(:record_update_job_error).with(
error_type: "dependency_file_not_parseable",
error_details: { "file-path": "path/to/file", message: "a" }
)

perform_job
end
end

context "with a Dependabot::DependencyFileNotFound error" do
let(:error) { Dependabot::DependencyFileNotFound.new("path/to/file") }

Expand Down

0 comments on commit 43e0298

Please sign in to comment.