lib/aws/cfn/compiler/base.rb in aws-cfn-compiler-0.9.21 vs lib/aws/cfn/compiler/base.rb in aws-cfn-compiler-0.9.22

- old
+ new

@@ -20,21 +20,34 @@ @dynamic_items = {} @dynamic_references = {} @all_sections.each do |section| @dynamic_items[section] ||= {} @dynamic_references[section] ||= [] + @dynamic_reference_locations ||= {} end end def dynamic_item(section,resource,hash) abort! "Invalid section '#{section}'\nValid sections are: #{@all_sections.join(',')}" unless @all_sections.include?(section) @dynamic_items[section][resource] = hash end def dynamic_reference(section,resource) abort! "Invalid section '#{section}'\nValid sections are: #{@all_sections.join(',')}" unless @all_sections.include?(section) + + caller_rgxp = %r/([-\.\/\(\)\w]+):(\d+)(?::in `(\w+)')?/o + stack = caller()[0] + match = caller_rgxp.match(stack) + f = File.basename(match[1]) + l = Integer(match[2]) + # m = match[3] unless match[3].nil? + + # logger.warn("Referenced resource '#{resource}' does not (yet) exist in the section '#{section}' (From #{f} line #{l})") unless (@items.has_key?(section) and @items[section].has_key?(resource)) + # @dynamic_references[section] << resource + @dynamic_reference_locations[resource] ||= {} + @dynamic_reference_locations[resource][section] = [f,l] end def _uniq_names(arr) names = {} arr.map { |n| names[n] = nil } @@ -133,10 +146,14 @@ net = (_uniq_names(refs.keys+@dynamic_references['Mappings']+@dynamic_references['Parameters']+@dynamic_references['Resources'])-names) unless net.empty? @logger.error '!!! Unknown references !!!' net.each do |name| - @logger.error " #{name} from #{refs[name][0]}:#{refs[name][1]}" + if refs.include?(name) + @logger.error " #{name} from #{refs[name][0]}:#{refs[name][1]}" + else + @logger.error " #{name} from #{@dynamic_reference_locations[name].map{ |s,a| "#{s}:#{a[0]} line #{a[1]}" }.join(',')}" + end end abort! end net = (prms+@dynamic_items['Parameters'].keys-refs.keys-@dynamic_references['Parameters']) unless net.empty?