Skip to content

Commit b3403d1

Browse files
committed
Clean up catalog validator
1 parent 763ccca commit b3403d1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/octocatalog-diff/util/catalogs.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,18 @@ def build_catalog(opts, logger = @logger)
238238
catalog
239239
end
240240

241-
# Validate a catalog in the parallel execution
242-
# The catalog validator can raise an exception to cause a more specific error message or
243-
# use a different class of exception than the default one here.
241+
# The catalog validator method can indicate failure one of two ways:
242+
# - Raise an exception (this is preferred, since it gives a specific error message)
243+
# - Return false (supported but discouraged, since it only surfaces a generic error)
244244
# @param catalog [OctocatalogDiff::Catalog] Catalog object
245245
# @param logger [Logger] Logger object (presently unused)
246246
# @param args [Hash] Additional arguments set specifically for validator
247+
# @return [Boolean] Return true if catalog is valid, false otherwise
247248
def catalog_validator(catalog = nil, _logger = @logger, args = {})
248-
return false unless catalog.is_a?(OctocatalogDiff::Catalog)
249-
catalog.validate_references if args[:task] == :to
250-
return true if catalog.valid?
251-
raise OctocatalogDiff::Errors::CatalogError, "Catalog failed: #{catalog.error_message}"
249+
raise ArgumentError, "Expects a catalog, got #{catalog.class}" unless catalog.is_a?(OctocatalogDiff::Catalog)
250+
raise OctocatalogDiff::Errors::CatalogError, "Catalog failed: #{catalog.error_message}" unless catalog.valid?
251+
catalog.validate_references if args[:task] == :to # Raises exception for broken references
252+
true
252253
end
253254
end
254255
end

0 commit comments

Comments
 (0)