Skip to content

Commit dad58e5

Browse files
author
Kevin Paulisse
committed
Resolve exception when array is empty
1 parent 2839d11 commit dad58e5

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

lib/octocatalog-diff/catalog.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ def validate_references
194194
missing << missing_resources.map { |missing_target| { source: x, target_type: r, target_value: missing_target } }
195195
end
196196
end
197-
missing.flatten!.compact!
197+
missing.flatten!
198+
missing.compact!
198199
return if missing.empty?
199200

200201
# At this point there is at least one broken/missing reference. Format an error message and
@@ -204,15 +205,15 @@ def validate_references
204205
# exec[subscribe caller 2] -> subscribe[Exec[subscribe target]]; exec[subscribe caller 2] ->
205206
# subscribe[Exec[subscribe target 2]]
206207
# ---
207-
reference_string = missing.map do |obj|
208+
formatted_references = missing.map do |obj|
208209
# obj[:target_value] can be a string or an array. If it's an array, break apart the
209210
# array and create one error message per element.
210211
src = "#{obj[:source]['type'].downcase}[#{obj[:source]['title']}]"
211212
tgv = obj[:target_value].is_a?(Array) ? obj[:target_value] : [obj[:target_value]]
212213
tgv.map { |tv| "#{src} -> #{obj[:target_type].downcase}[#{tv}]" }.join('; ')
213-
end.join('; ')
214+
end
214215
plural = missing.size == 1 ? '' : 's'
215-
raise ReferenceValidationError, "Catalog has broken reference#{plural}: #{reference_string}"
216+
raise ReferenceValidationError, "Catalog has broken reference#{plural}: #{formatted_references.join('; ')}"
216217
end
217218

218219
private

0 commit comments

Comments
 (0)