Skip to content

Commit 554f573

Browse files
author
Kevin Paulisse
committed
Simplify logic around reference error generation
1 parent dad58e5 commit 554f573

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

lib/octocatalog-diff/catalog.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,17 @@ def validate_references
206206
# subscribe[Exec[subscribe target 2]]
207207
# ---
208208
formatted_references = missing.map do |obj|
209-
# obj[:target_value] can be a string or an array. If it's an array, break apart the
210-
# array and create one error message per element.
209+
# obj[:target_value] can be a string or an array. If it's an array, create a
210+
# separate error message per element of that array. This allows the total number
211+
# of errors to be correct.
211212
src = "#{obj[:source]['type'].downcase}[#{obj[:source]['title']}]"
212-
tgv = obj[:target_value].is_a?(Array) ? obj[:target_value] : [obj[:target_value]]
213-
tgv.map { |tv| "#{src} -> #{obj[:target_type].downcase}[#{tv}]" }.join('; ')
213+
target_val = obj[:target_value].is_a?(Array) ? obj[:target_value] : [obj[:target_value]]
214+
target_val.map { |tv| "#{src} -> #{obj[:target_type].downcase}[#{tv}]" }
214215
end
215-
plural = missing.size == 1 ? '' : 's'
216-
raise ReferenceValidationError, "Catalog has broken reference#{plural}: #{formatted_references.join('; ')}"
216+
formatted_references.flatten!
217+
plural = formatted_references.size == 1 ? '' : 's'
218+
errors = formatted_references.join('; ')
219+
raise ReferenceValidationError, "Catalog has broken reference#{plural}: #{errors}"
217220
end
218221

219222
private

0 commit comments

Comments
 (0)