puppetlabs/puppet · error · Puppet::Error
Error while parsing 'todate'
Error message
Error while parsing 'todate'
What it means
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.
Source
Thrown at lib/puppet/indirector/file_bucket_file/file.rb:55
Puppet.info _("FileBucket read %{checksum}") % { checksum: checksum }
model.new(Puppet::FileSystem.binread(contents_file))
end
else
nil
end
end
def list(request)
if request.remote?
raise Puppet::Error, _("Listing remote file buckets is not allowed")
end
fromdate = request.options[:fromdate] || "0:0:0 1-1-1970"
todate = request.options[:todate] || Time.now.strftime("%F %T")
begin
to = Time.parse(todate)
rescue ArgumentError
raise Puppet::Error, _("Error while parsing 'todate'")
end
begin
from = Time.parse(fromdate)
rescue ArgumentError
raise Puppet::Error, _("Error while parsing 'fromdate'")
end
# Setting hash's default value to [], needed by the following loop
bucket = Hash.new { [] }
msg = ''.dup
# Get all files with mtime between 'from' and 'to'
Pathname.new(request.options[:bucket_path]).find { |item|
next unless item.file? and item.basename.to_s == "paths"
filenames = item.read.strip.split("\n")
filestat = Time.parse(item.stat.mtime.to_s)
next unless from <= filestat and filestat <= to
filenames.each do |filename|View on GitHub (pinned to e227c27540)
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.
Example fix
# before puppet filebucket list --fromdate "2024-01-01" --todate not-a-date # Error: Error while parsing 'todate' # after puppet filebucket list --fromdate "2024-01-01" --todate "2024-12-31 23:59:59"
Defensive patterns
Strategy: validation
Validate before calling
require 'time' def parseable_date?(value) Time.parse(value) true rescue ArgumentError false end abort 'invalid --todate, expected YYYY-MM-DD HH:MM:SS' unless parseable_date?(todate)
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error while parsing 'fromdate'
- Need exactly two arguments: filebucket diff <file_a> <file_b
- Could not back up %{file}: %{detail}
- Diff is not supported on this platform
- Please provide a file or checksum to diff with
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/8cf68804e8d41262.
Report an issue: GitHub.