{"record":{"id":"5ef2e25db6609259","repo":"puppetlabs/puppet","slug":"command-must-be-a-string-or-array-string-got-val","errorCode":null,"errorMessage":"Command must be a String or Array<String>, got value of class %{klass}","messagePattern":"Command must be a String or Array<String>, got value of class %(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/type/exec.rb","lineNumber":218,"sourceCode":"        succeeds, any output produced will be logged at the instance's\n        normal log level (usually `notice`), but if the command fails\n        (meaning its return code does not match the specified code) then\n        any output is logged at the `err` log level.\n\n        Multiple `exec` resources can use the same `command` value; Puppet\n        only uses the resource title to ensure `exec`s are unique.\n\n        On *nix platforms, the command can be specified as an array of\n        strings and Puppet will invoke it using the more secure method of\n        parameterized system calls. For example, rather than executing the\n        malicious injected code, this command will echo it out:\n\n            command => ['/bin/echo', 'hello world; rm -rf /']\n      \"\n\n      validate do |command|\n        unless command.is_a?(String) || command.is_a?(Array)\n          raise ArgumentError, _(\"Command must be a String or Array<String>, got value of class %{klass}\") % { klass: command.class }\n        end\n      end\n    end\n\n    newparam(:path) do\n      desc \"The search path used for command execution.\n        Commands must be fully qualified if no path is specified.  Paths\n        can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list.\"\n\n      # Support both arrays and colon-separated fields.\n      def value=(*values)\n        @value = values.flatten.collect { |val|\n          val.split(File::PATH_SEPARATOR)\n        }.flatten\n      end\n    end\n\n    newparam(:user) do","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/type/exec.rb#L200-L236","documentation":"The exec type's command parameter validates that its value is a String or an Array (of strings for parameterized invocation). Any other class — most commonly nil from an undef variable, or a Hash — raises ArgumentError 'Command must be a String or Array<String>'. This happens at resource validation time, before any execution attempt.","triggerScenarios":"exec { 'x': command => $cmd } where $cmd is undef (hiera key missing, variable from a class not evaluated); command built by template interpolation that returned nil; passing a Hash from a lookup; arrays containing nil elements are not caught here but fail later at execution.","commonSituations":"Profile data refactors where a profile silently stops setting a variable an exec depends on; deep hiera merges shadowing a key with undef; node groups missing a classification layer; optional execs whose enabling class was renamed.","solutions":["Default the variable: $cmd = pick($cmd, '/bin/true') or set a hiera default_value","Verify the data path: puppet lookup --node <n> profile::exec::command --explain shows which layer failed to supply it","Conditionally declare the exec only when the command is set (if $cmd { exec { ... } })","Ensure the value is a plain string, not structured data"],"exampleFix":"# before\nexec { 'run-migration': command => $migration_cmd } # undef => ArgumentError\n\n# after\n$migration_cmd = pick(lookup('app::migration_cmd', { 'default_value' => undef }), '/bin/true')\nexec { 'run-migration': command => $migration_cmd }","handlingStrategy":"validation","validationCode":"$cmd = pick($cmd, '/bin/true')\n# or in Ruby:\nraise ArgumentError, 'command is required' unless command.is_a?(String) || command.is_a?(Array)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default command variables with pick() or hiera default_value","Declare exec resources only when their data is present (if $cmd { exec { ... } })","Use puppet lookup --explain on nodes where the exec appears without a command"],"tags":["puppet","exec","command","undef-variable","hiera"],"backgroundTag":"invalid-attribute-type","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}