Skip to content

Commit bfd9f8e

Browse files
Removing Support file specific error handling
1 parent 92a8368 commit bfd9f8e

File tree

2 files changed

+6
-140
lines changed

2 files changed

+6
-140
lines changed

updater/lib/dependabot/dependency_change_builder.rb

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ module Dependabot
2525
class DependencyChangeBuilder
2626
extend T::Sig
2727

28-
SUPPORT_FILE_WARNING_NAME_LIMIT = 10
29-
3028
sig do
3129
params(
3230
job: Dependabot::Job,
@@ -69,17 +67,14 @@ def initialize(job:, dependency_files:, updated_dependencies:, change_source:, n
6967
@updated_dependencies = updated_dependencies
7068
@change_source = change_source
7169
@notices = notices
72-
@support_files_only_diagnostics = T.let(nil, T.nilable(String))
7370
end
7471

7572
sig { returns(Dependabot::DependencyChange) }
7673
def run
7774
updated_files = generate_dependency_files
7875

7976
unless updated_files.any?
80-
error_message = "FileUpdater failed to update any files for: #{dependency_info_for_error}"
81-
error_message += "; #{support_files_only_diagnostics}" if support_files_only_diagnostics
82-
raise DependabotError, error_message
77+
raise DependabotError, "FileUpdater failed to update any files for: #{dependency_info_for_error}"
8378
end
8479

8580
# Remove any unchanged dependencies from the updated list
@@ -120,9 +115,6 @@ def run
120115
sig { returns(T::Array[Dependabot::Notice]) }
121116
attr_reader :notices
122117

123-
sig { returns(T.nilable(String)) }
124-
attr_reader :support_files_only_diagnostics
125-
126118
sig { returns(T.nilable(String)) }
127119
def source_dependency_name
128120
return nil unless change_source.is_a? Dependabot::Dependency
@@ -167,44 +159,9 @@ def generate_dependency_files
167159
@notices.concat(updater_notices)
168160

169161
updated_files = all_files.reject(&:support_file?)
170-
add_support_files_only_diagnostics(all_files: all_files, updated_files: updated_files)
171-
172162
updated_files
173163
end
174164

175-
sig do
176-
params(
177-
all_files: T::Array[Dependabot::DependencyFile],
178-
updated_files: T::Array[Dependabot::DependencyFile]
179-
).void
180-
end
181-
def add_support_files_only_diagnostics(all_files:, updated_files:)
182-
return unless all_files.any? && updated_files.empty?
183-
184-
support_file_names = naturally_sorted_names(all_files.select(&:support_file?).map(&:name).uniq)
185-
listed_support_file_names = support_file_names.first(SUPPORT_FILE_WARNING_NAME_LIMIT)
186-
omitted_support_file_count = support_file_names.length - listed_support_file_names.length
187-
support_file_list = listed_support_file_names.join(", ")
188-
support_file_list += " (and #{omitted_support_file_count} more)" if omitted_support_file_count.positive?
189-
190-
diagnostics = "FileUpdater returned only support files: #{support_file_list}"
191-
@support_files_only_diagnostics = diagnostics
192-
Dependabot.logger.warn("#{diagnostics} for: #{dependency_info_for_error}")
193-
end
194-
195-
sig { params(names: T::Array[String]).returns(T::Array[String]) }
196-
def naturally_sorted_names(names)
197-
names.sort_by { |name| natural_sort_segments(name) }
198-
end
199-
200-
sig { params(name: String).returns(T::Array[[Integer, T.any(Integer, String)]]) }
201-
def natural_sort_segments(name)
202-
segments = T.cast(name.scan(/\d+|\D+/), T::Array[String])
203-
segments.map do |segment|
204-
segment.match?(/\A\d+\z/) ? [0, segment.to_i] : [1, segment.downcase]
205-
end
206-
end
207-
208165
sig { returns(String) }
209166
def dependency_names_for_error
210167
format_names(updated_dependencies.map(&:name))

updater/spec/dependabot/dependency_change_builder_spec.rb

Lines changed: 5 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,6 @@ def dependency_group_source
125125
Dependabot::DependencyGroup.new(name: "dummy-pkg-*", rules: { patterns: ["dummy-pkg-*"] })
126126
end
127127

128-
def build_support_files(names)
129-
names.map do |name|
130-
Dependabot::DependencyFile.new(
131-
name: name,
132-
content: "content",
133-
directory: "/",
134-
support_file: true
135-
)
136-
end
137-
end
138-
139128
context "when the source is a lead dependency" do
140129
let(:change_source) { lead_dependency_change_source }
141130

@@ -252,31 +241,19 @@ def build_support_files(names)
252241
stub_file_updater(updated_dependency_files: updated_support_files, notices: updater_notices)
253242
end
254243

255-
it "warns with excluded support file names" do
256-
expect(Dependabot.logger)
257-
.to receive(:warn)
258-
.with(satisfy { |message|
259-
message.include?("FileUpdater returned only support files") &&
260-
message.include?("for: #{single_dependency_info}") &&
261-
message.include?("sub_dep") &&
262-
message.include?("sub_dep.lock") &&
263-
!message.include?("(and")
264-
})
265-
244+
it "raises a generic no-files error" do
266245
expect { create_change }
267246
.to raise_error(
268247
Dependabot::DependabotError,
269-
"FileUpdater failed to update any files for: dummy-pkg-b (1.1.0 → 1.2.0); " \
270-
"FileUpdater returned only support files: sub_dep, sub_dep.lock"
248+
"FileUpdater failed to update any files for: dummy-pkg-b (1.1.0 → 1.2.0)"
271249
)
272250
end
273251

274252
it "collects notices before raising" do
275253
expect { create_change }
276254
.to raise_error(
277255
Dependabot::DependabotError,
278-
"FileUpdater failed to update any files for: dummy-pkg-b (1.1.0 → 1.2.0); " \
279-
"FileUpdater returned only support files: sub_dep, sub_dep.lock"
256+
"FileUpdater failed to update any files for: dummy-pkg-b (1.1.0 → 1.2.0)"
280257
)
281258

282259
expect(notices).to eq(updater_notices)
@@ -298,79 +275,11 @@ def build_support_files(names)
298275
stub_file_updater(updated_dependency_files: support_files)
299276
end
300277

301-
it "raises a diagnostics error with sorted and unique dependency names" do
302-
expect { create_change }
303-
.to raise_error(
304-
Dependabot::DependabotError,
305-
"FileUpdater failed to update any files for: dummy-pkg-a, dummy-pkg-b; " \
306-
"FileUpdater returned only support files: sub_dep, sub_dep.lock"
307-
)
308-
end
309-
end
310-
311-
context "when support file names exceed warning limit" do
312-
let(:change_source) { lead_dependency_change_source }
313-
let(:support_files) do
314-
file_names = Array.new(described_class::SUPPORT_FILE_WARNING_NAME_LIMIT + 1) do |index|
315-
"support_#{index}.txt"
316-
end
317-
build_support_files(file_names)
318-
end
319-
320-
before do
321-
stub_file_updater(updated_dependency_files: support_files)
322-
end
323-
324-
it "adds omitted count to diagnostics" do
325-
expected_support_files = Array.new(described_class::SUPPORT_FILE_WARNING_NAME_LIMIT) do |index|
326-
"support_#{index}.txt"
327-
end.join(", ")
328-
278+
it "raises a no-files error listing sorted and unique dependency names" do
329279
expect { create_change }
330280
.to raise_error(
331281
Dependabot::DependabotError,
332-
"FileUpdater failed to update any files for: dummy-pkg-b (1.1.0 → 1.2.0); " \
333-
"FileUpdater returned only support files: #{expected_support_files} (and 1 more)"
334-
)
335-
end
336-
end
337-
338-
context "when support file names include multi-digit suffixes" do
339-
let(:change_source) { lead_dependency_change_source }
340-
let(:support_files) do
341-
build_support_files([10, 2, 1].map { |index| "support_#{index}.txt" })
342-
end
343-
344-
before do
345-
stub_file_updater(updated_dependency_files: support_files)
346-
end
347-
348-
it "orders support file names naturally in diagnostics" do
349-
expect { create_change }
350-
.to raise_error(
351-
Dependabot::DependabotError,
352-
"FileUpdater failed to update any files for: dummy-pkg-b (1.1.0 → 1.2.0); " \
353-
"FileUpdater returned only support files: support_1.txt, support_2.txt, support_10.txt"
354-
)
355-
end
356-
end
357-
358-
context "when support file names differ in casing" do
359-
let(:change_source) { lead_dependency_change_source }
360-
let(:support_files) do
361-
build_support_files(["Support_2.txt", "support_10.txt", "support_1.txt"])
362-
end
363-
364-
before do
365-
stub_file_updater(updated_dependency_files: support_files)
366-
end
367-
368-
it "orders support file names naturally regardless of case" do
369-
expect { create_change }
370-
.to raise_error(
371-
Dependabot::DependabotError,
372-
"FileUpdater failed to update any files for: dummy-pkg-b (1.1.0 → 1.2.0); " \
373-
"FileUpdater returned only support files: support_1.txt, Support_2.txt, support_10.txt"
282+
"FileUpdater failed to update any files for: dummy-pkg-a, dummy-pkg-b"
374283
)
375284
end
376285
end

0 commit comments

Comments
 (0)