{"record":{"id":"8cf68804e8d41262","repo":"puppetlabs/puppet","slug":"error-while-parsing-todate","errorCode":null,"errorMessage":"Error while parsing 'todate'","messagePattern":"Error while parsing 'todate'","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/indirector/file_bucket_file/file.rb","lineNumber":55,"sourceCode":"          Puppet.info _(\"FileBucket read %{checksum}\") % { checksum: checksum }\n          model.new(Puppet::FileSystem.binread(contents_file))\n        end\n      else\n        nil\n      end\n    end\n\n    def list(request)\n      if request.remote?\n        raise Puppet::Error, _(\"Listing remote file buckets is not allowed\")\n      end\n\n      fromdate = request.options[:fromdate] || \"0:0:0 1-1-1970\"\n      todate = request.options[:todate] || Time.now.strftime(\"%F %T\")\n      begin\n        to = Time.parse(todate)\n      rescue ArgumentError\n        raise Puppet::Error, _(\"Error while parsing 'todate'\")\n      end\n      begin\n        from = Time.parse(fromdate)\n      rescue ArgumentError\n        raise Puppet::Error, _(\"Error while parsing 'fromdate'\")\n      end\n      # Setting hash's default value to [], needed by the following loop\n      bucket = Hash.new { [] }\n      msg = ''.dup\n      # Get all files with mtime between 'from' and 'to'\n      Pathname.new(request.options[:bucket_path]).find { |item|\n        next unless item.file? and item.basename.to_s == \"paths\"\n\n        filenames = item.read.strip.split(\"\\n\")\n        filestat = Time.parse(item.stat.mtime.to_s)\n        next unless from <= filestat and filestat <= to\n\n        filenames.each do |filename|","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/indirector/file_bucket_file/file.rb#L37-L73","documentation":"The FileBucket list action parses the todate option with Ruby's Time.parse; the default is Time.now formatted '%F %T'. If the string is not a recognized time expression, the ArgumentError from Time.parse is re-raised as Puppet::Error \"Error while parsing 'todate'\". This is pure client-side input validation, not a server problem.","triggerScenarios":"Passing an unparseable --todate to 'puppet filebucket list': values like 'not-a-date', '2024/13/45', or a value mangled by shell word-splitting so only a fragment reaches the option.","commonSituations":"Locale-ambiguous or day/month-swapped dates; dates copied from docs with stray characters; unquoted values containing spaces in scripts; date strings generated from empty variables.","solutions":["Use the same explicit format as the default: 'YYYY-MM-DD HH:MM:SS', e.g. --todate '2024-12-31 23:59:59'.","Omit --todate entirely; it defaults to the current time.","Quote the whole value in the shell so it arrives as one argument.","Pre-validate scripted dates with Time.parse in a rescue block before invoking the CLI."],"exampleFix":"# before\npuppet filebucket list --fromdate \"2024-01-01\" --todate not-a-date\n# Error: Error while parsing 'todate'\n\n# after\npuppet filebucket list --fromdate \"2024-01-01\" --todate \"2024-12-31 23:59:59\"","handlingStrategy":"validation","validationCode":"require 'time'\n\ndef parseable_date?(value)\n  Time.parse(value)\n  true\nrescue ArgumentError\n  false\nend\n\nabort 'invalid --todate, expected YYYY-MM-DD HH:MM:SS' unless parseable_date?(todate)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on ISO 8601 'YYYY-MM-DD HH:MM:SS' in all tooling.","Validate date options in wrapper scripts before calling the puppet CLI.","Quote date arguments so shells cannot split them."],"tags":["puppet","filebucket","date-parsing","cli-arguments","input-validation"],"backgroundTag":"invalid-date-format","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}