Method: Puppet::Parser::Scope#variable_not_found

Defined in:
lib/puppet/parser/scope.rb

#variable_not_found(name, reason = nil) ⇒ Object



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/puppet/parser/scope.rb', line 522

def variable_not_found(name, reason = nil)
  # Built in variables and numeric variables always exist
  if BUILT_IN_VARS.include?(name) || name =~ Puppet::Pops::Patterns::NUMERIC_VAR_NAME
    return nil
  end

  begin
    throw(:undefined_variable, reason)
  rescue UNCAUGHT_THROW_EXCEPTION
    case Puppet[:strict]
    when :off
      # do nothing
    when :warning
      Puppet.warn_once(UNDEFINED_VARIABLES_KIND, _("Variable: %{name}") % { name: name },
                       _("Undefined variable '%{name}'; %{reason}") % { name: name, reason: reason })
    when :error
      if Puppet.lookup(:avoid_hiera_interpolation_errors) { false }
        Puppet.warn_once(UNDEFINED_VARIABLES_KIND, _("Variable: %{name}") % { name: name },
                         _("Interpolation failed with '%{name}', but compilation continuing; %{reason}") % { name: name, reason: reason })
      else
        raise ArgumentError, _("Undefined variable '%{name}'; %{reason}") % { name: name, reason: reason }
      end
    end
  end
  nil
end