javan/whenever · error
[fail] Can't find file: #{@options[:file]}
Error message
[fail] Can't find file: #{@options[:file]} What it means
The whenever CLI defaults to loading config/schedule.rb relative to the current working directory. In initialize it checks that the file exists; if it does not (and you are not running --clear-crontab, which skips the check), it warns and calls return_or_exit(false), exiting with status 1 in the default console mode. This is a hard exit, not an exception, so it typically surfaces as a failed deploy step or shell command.
Source
Thrown at lib/whenever/command_line.rb:19
require 'fileutils'
module Whenever
class CommandLine
def self.execute(options={})
new(options).run
end
def initialize(options={})
@options = options
@options[:crontab_command] ||= 'crontab'
@options[:file] ||= 'config/schedule.rb'
@options[:cut] ||= 0
@options[:identifier] ||= default_identifier
@options[:console] = true if @options[:console].nil?
if !File.exist?(@options[:file]) && @options[:clear].nil?
warn("[fail] Can't find file: #{@options[:file]}")
return_or_exit(false)
end
if [@options[:update], @options[:write], @options[:clear]].compact.length > 1
warn("[fail] Can only update, write or clear. Choose one.")
return_or_exit(false)
end
unless @options[:cut].to_s =~ /[0-9]*/
warn("[fail] Can't cut negative lines from the crontab #{options[:cut]}")
return_or_exit(false)
end
@options[:cut] = @options[:cut].to_i
@timestamp = Time.now.to_s
end
def runView on GitHub (pinned to 756163ed1a)
Solutions
- cd to the application root (the directory containing config/) before running whenever.
- Point at the file explicitly: whenever -f config/schedule.rb, or pass an absolute path.
- Generate the file in a new project: `wheneverize .` creates config/schedule.rb.
- To tear down a crontab after the schedule file is gone, use whenever --clear-crontab — the existence check is skipped for clear.
Example fix
# before (run from wrong directory) cd /home/deploy && whenever --update-crontab myapp # after bash -c 'cd /srv/myapp/current && whenever --update-crontab myapp' # or point at the file directly whenever -f /srv/myapp/current/config/schedule.rb --update-crontab myapp
Defensive patterns
Strategy: validation
Validate before calling
schedule = File.expand_path('config/schedule.rb', app_root)
abort('no schedule file at ' + schedule + '; run `wheneverize .` or pass -f') unless File.exist?(schedule)
`whenever -f #{schedule} --update-crontab myapp` Type guard
def schedule_present?(path) File.exist?(File.expand_path(path)) end
Try / catch
begin
Whenever::CommandLine.execute(file: schedule)
rescue SystemExit => e
abort('whenever exited with status ' + e.status.to_s) unless e.success?
end Prevention
- Always run whenever from the application root, or pass an absolute -f path in scripts, cron entries, and CI.
- Commit config/schedule.rb to the repo after generating it with `wheneverize .`.
- In deploy scripts, cd to the release directory (or use the capistrano recipes, which already cd to the release path).
- Use --clear-crontab for teardown — it intentionally skips the file check.
When it happens
Trigger: Running `whenever` or `whenever --update-crontab` from a directory other than the Rails/app root (the default path config/schedule.rb resolves against cwd); -f/--load-file pointing at a typo'd or non-existent path; a fresh project where `wheneverize .` was never run; a schedule file kept at a non-default location without passing -f.
Common situations: SSH'd into a server and running whenever from $HOME instead of the release directory; CI pipelines whose working directory is not the repo root; deploy scripts invoking whenever without cd-ing to the app path; new apps where someone added the gem to the Gemfile but never generated the schedule file.
Related errors
- [fail] Can only update, write or clear. Choose one.
- [fail] Can't cut negative lines from the crontab #{options[:
- :command, :path, & :flags are required
- You cannot specify an ':at' when using the shortcuts for tim
- Time must be in minutes or higher
AI-assisted analysis of javan/whenever@756163ed1a (2026-08-21).
Data as JSON: /api/errors/882a6be728ce0d73.
Report an issue: GitHub.