{"record":{"id":"e6c3df261b5a23ea","repo":"puppetlabs/puppet","slug":"an-empty-mode-string-is-illegal","errorCode":null,"errorMessage":"An empty mode string is illegal","messagePattern":"An empty mode string is illegal","errorType":"validation","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/symbolic_file_mode.rb","lineNumber":53,"sourceCode":"\n    # We need to treat integers as octal numbers.\n    #\n    # \"A numeric mode is from one to four octal digits (0-7), derived by adding\n    # up the bits with values 4, 2, and 1. Omitted digits are assumed to be\n    # leading zeros.\"\n    case value\n    when Numeric\n      value.to_s(8)\n    when /^0?[0-7]{1,4}$/\n      value.to_i(8).to_s(8) # strip leading 0's\n    else\n      value\n    end\n  end\n\n  def symbolic_mode_to_int(modification, to_mode = 0, is_a_directory = false)\n    if modification.nil? or modification == ''\n      raise Puppet::Error, _(\"An empty mode string is illegal\")\n    elsif modification =~ /^[0-7]+$/\n      return modification.to_i(8)\n    elsif modification =~ /^\\d+$/\n      raise Puppet::Error, _(\"Numeric modes must be in octal, not decimal!\")\n    end\n\n    fail _(\"non-numeric current mode (%{mode})\") % { mode: to_mode.inspect } unless to_mode.is_a?(Numeric)\n\n    original_mode = {\n      's' => (to_mode & 0o7000) >> 9,\n      'u' => (to_mode & 0o0700) >> 6,\n      'g' => (to_mode & 0o0070) >> 3,\n      'o' => (to_mode & 0o0007) >> 0,\n      # Are there any execute bits set in the original mode?\n      'any x?' => (to_mode & 0o0111) != 0\n    }\n    final_mode = {\n      's' => original_mode['s'],","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/symbolic_file_mode.rb#L35-L71","documentation":"Raised by Puppet::Util::SymbolicMode.symbolic_mode_to_int when the mode argument is nil or the empty string. The parser refuses to compute a file mode from nothing rather than silently applying mode 0.","triggerScenarios":"symbolic_mode_to_int('') or symbolic_mode_to_int(nil); in manifest terms, a file resource whose mode property resolves to '' or undef (e.g. mode => $var where the variable is empty or undef interpolated to an empty string).","commonSituations":"A Hiera lookup key feeding the mode parameter is missing; manifest variables that are conditionally set; templates that render an empty mode value.","solutions":["Set an explicit mode such as mode => '0644'.","If the mode is optional, guard the resource or calling code so the mode is only passed when it has a value.","Fix the Hiera/lookup data so the mode variable is populated."],"exampleFix":"# before (mode_var is undef/empty)\nfile { '/etc/app.conf': mode => $mode_var }\n\n# after\nfile { '/etc/app.conf': mode => pick($mode_var, '0644') }","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'mode must be a non-empty string' if mode.nil? || mode.to_s.empty?\nPuppet::Util::SymbolicMode.symbolic_mode_to_int(mode)","typeGuard":"def valid_mode_input?(m)\n  m.is_a?(String) && !m.empty?\nend","tryCatchPattern":null,"preventionTips":["Default mode parameters with pick()/Hiera defaults.","Lint manifests for empty parameter values.","Unit-test mode inputs when wrapping symbolic_mode_to_int."],"tags":["puppet","file-mode","permissions","validation"],"backgroundTag":"invalid-file-mode","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}