@@ -33,15 +33,18 @@ class Catalog
33
33
def initialize ( options = { } )
34
34
@options = options
35
35
36
+ # The compilation directory can be overridden, e.g. when testing
37
+ @override_compilation_dir = options [ :compilation_dir ]
38
+
36
39
# Call appropriate backend for catalog generation
37
40
@catalog_obj = backend ( options )
38
41
39
42
# The catalog is not built yet, except if the backend has no build method
40
43
@built = false
41
44
build unless @catalog_obj . respond_to? ( :build )
42
45
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
45
48
end
46
49
47
50
# 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))
69
72
70
73
# Perform post-generation processing of the catalog
71
74
return unless valid?
75
+
76
+ validate_references
77
+ return unless valid?
78
+
72
79
unless @catalog_obj . respond_to? ( :convert_file_resources ) && @catalog_obj . convert_file_resources == false
73
80
if @options . fetch ( :compare_file_text , false )
74
81
OctocatalogDiff ::CatalogUtil ::FileResources . convert_file_resources ( self , environment )
@@ -182,6 +189,10 @@ def valid?
182
189
# Raise a OctocatalogDiff::Errors::ReferenceValidationError for any found to be missing.
183
190
# Uses @options[:validate_references] to influence which references are checked.
184
191
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
+
185
196
# Skip out early if no reference validation has been requested.
186
197
unless @options [ :validate_references ] . is_a? ( Array ) && @options [ :validate_references ] . any?
187
198
return
@@ -208,7 +219,7 @@ def validate_references
208
219
# At this point there is at least one broken/missing reference. Format an error message and raise.
209
220
errors = format_missing_references ( missing )
210
221
plural = errors =~ /;/ ? 's' : ''
211
- raise OctocatalogDiff :: Errors :: ReferenceValidationError , "Catalog has broken reference#{ plural } : #{ errors } "
222
+ self . error_message = "Catalog has broken reference#{ plural } : #{ errors } "
212
223
end
213
224
214
225
private
0 commit comments