@@ -33,15 +33,18 @@ class Catalog
3333 def initialize ( options = { } )
3434 @options = options
3535
36+ # The compilation directory can be overridden, e.g. when testing
37+ @override_compilation_dir = options [ :compilation_dir ]
38+
3639 # Call appropriate backend for catalog generation
3740 @catalog_obj = backend ( options )
3841
3942 # The catalog is not built yet, except if the backend has no build method
4043 @built = false
4144 build unless @catalog_obj . respond_to? ( :build )
4245
43- # The compilation directory can be overridden, e.g. when testing
44- @override_compilation_dir = nil
46+ # Keep track of whether references have been validated yet
47+ @references_validated = false
4548 end
4649
4750 # Build catalog - this method needs to be called to build the catalog. It is separate due to
@@ -69,6 +72,10 @@ def build(logger = Logger.new(StringIO.new))
6972
7073 # Perform post-generation processing of the catalog
7174 return unless valid?
75+
76+ validate_references
77+ return unless valid?
78+
7279 unless @catalog_obj . respond_to? ( :convert_file_resources ) && @catalog_obj . convert_file_resources == false
7380 if @options . fetch ( :compare_file_text , false )
7481 OctocatalogDiff ::CatalogUtil ::FileResources . convert_file_resources ( self , environment )
@@ -182,6 +189,10 @@ def valid?
182189 # Raise a OctocatalogDiff::Errors::ReferenceValidationError for any found to be missing.
183190 # Uses @options[:validate_references] to influence which references are checked.
184191 def validate_references
192+ # If we've already done the validation, don't do it again
193+ return if @references_validated
194+ @references_validated = true
195+
185196 # Skip out early if no reference validation has been requested.
186197 unless @options [ :validate_references ] . is_a? ( Array ) && @options [ :validate_references ] . any?
187198 return
@@ -208,7 +219,7 @@ def validate_references
208219 # At this point there is at least one broken/missing reference. Format an error message and raise.
209220 errors = format_missing_references ( missing )
210221 plural = errors =~ /;/ ? 's' : ''
211- raise OctocatalogDiff :: Errors :: ReferenceValidationError , "Catalog has broken reference#{ plural } : #{ errors } "
222+ self . error_message = "Catalog has broken reference#{ plural } : #{ errors } "
212223 end
213224
214225 private
0 commit comments