Skip to content

Commit

Permalink
Handle DependencyFileNotParseable error on Updater.run
Browse files Browse the repository at this point in the history
  • Loading branch information
amazimbe committed Jan 13, 2025
1 parent 21a9544 commit 94d2bed
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
15 changes: 10 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 StandardError => e
handle_parser_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
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 94d2bed

Please sign in to comment.