puppetlabs/puppet · error · ArgumentError

Cannot use '%{a_term}' and '%{b_term}' at the same time

Error message

Cannot use '%{a_term}' and '%{b_term}' at the same time

What it means

PAL's assert_mutually_exclusive raises ArgumentError when both of a forbidden pair are truthy. It guards the (manifest_file, code_string) pair and the (env_dir, envpath) pair on the PAL entry points - only one of each pair may be supplied.

Source

Thrown at lib/puppet/pal/pal_impl.rb:573

    Puppet::Pops::Types::TypeFactory.pattern(/\A[a-z][a-z0-9_]*\z/), Puppet::Pops::Types::TypeFactory.data
  )

  def self.assert_type(type, value, what, allow_nil = false)
    Puppet::Pops::Types::TypeAsserter.assert_instance_of(nil, type, value, allow_nil) { _('Puppet Pal: %{what}') % { what: what } }
  end

  def self.assert_non_empty_string(s, what, allow_nil = false)
    assert_type(T_STRING, s, what, allow_nil)
  end

  def self.assert_optionally_empty_array(a, what, allow_nil = false)
    assert_type(T_STRING_ARRAY, a, what, allow_nil)
  end
  private_class_method :assert_optionally_empty_array

  def self.assert_mutually_exclusive(a, b, a_term, b_term)
    if a && b
      raise ArgumentError, _("Cannot use '%{a_term}' and '%{b_term}' at the same time") % { a_term: a_term, b_term: b_term }
    end
  end
  private_class_method :assert_mutually_exclusive

  def self.assert_block_given(block)
    if block.nil?
      raise ArgumentError, _("A block must be given")
    end
  end
  private_class_method :assert_block_given
end
end

View on GitHub (pinned to e227c27540)

Solutions

  1. Supply only one of each pair (manifest_file or code_string; env_dir or envpath)
  2. In wrappers, apply precedence before delegating: manifest_file = nil if code_string
  3. Raise your own descriptive error early when the caller sets both

Example fix

# before
Puppet::Pal.in_environment('prod', env_dir: d, envpath: p) { |c| }

# after
Puppet::Pal.in_environment('prod', env_dir: d) { |c| }
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, 'pass env_dir OR envpath, not both' if env_dir && envpath

Prevention

When it happens

Trigger: Passing manifest_file AND code_string to a PAL compiler call; passing env_dir AND envpath to in_environment.

Common situations: Wrapper APIs forwarding user options straight into PAL so both get set from config files; option precedence never decided upstream.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/98f250ecf0a8a9b2. Report an issue: GitHub.