{"record":{"id":"882a6be728ce0d73","repo":"javan/whenever","slug":"fail-can-t-find-file-options-file","errorCode":null,"errorMessage":"[fail] Can't find file: #{@options[:file]}","messagePattern":"\\[fail\\] Can't find file: #(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/whenever/command_line.rb","lineNumber":19,"sourceCode":"require 'fileutils'\n\nmodule Whenever\n  class CommandLine\n    def self.execute(options={})\n      new(options).run\n    end\n\n    def initialize(options={})\n      @options = options\n\n      @options[:crontab_command] ||= 'crontab'\n      @options[:file]            ||= 'config/schedule.rb'\n      @options[:cut]             ||= 0\n      @options[:identifier]      ||= default_identifier\n      @options[:console]    = true if @options[:console].nil?\n\n      if !File.exist?(@options[:file]) && @options[:clear].nil?\n        warn(\"[fail] Can't find file: #{@options[:file]}\")\n        return_or_exit(false)\n      end\n\n      if [@options[:update], @options[:write], @options[:clear]].compact.length > 1\n        warn(\"[fail] Can only update, write or clear. Choose one.\")\n        return_or_exit(false)\n      end\n\n      unless @options[:cut].to_s =~ /[0-9]*/\n        warn(\"[fail] Can't cut negative lines from the crontab #{options[:cut]}\")\n        return_or_exit(false)\n      end\n      @options[:cut] = @options[:cut].to_i\n\n      @timestamp = Time.now.to_s\n    end\n\n    def run","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/javan/whenever/blob/756163ed1aa928c8abd629aa2f4904bc5226538c/lib/whenever/command_line.rb#L1-L37","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before (run from wrong directory)\ncd /home/deploy && whenever --update-crontab myapp\n\n# after\nbash -c 'cd /srv/myapp/current && whenever --update-crontab myapp'\n# or point at the file directly\nwhenever -f /srv/myapp/current/config/schedule.rb --update-crontab myapp","handlingStrategy":"validation","validationCode":"schedule = File.expand_path('config/schedule.rb', app_root)\nabort('no schedule file at ' + schedule + '; run `wheneverize .` or pass -f') unless File.exist?(schedule)\n`whenever -f #{schedule} --update-crontab myapp`","typeGuard":"def schedule_present?(path)\n  File.exist?(File.expand_path(path))\nend","tryCatchPattern":"begin\n  Whenever::CommandLine.execute(file: schedule)\nrescue SystemExit => e\n  abort('whenever exited with status ' + e.status.to_s) unless e.success?\nend","preventionTips":["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."],"tags":["ruby","cli","cron","file-not-found","whenever"],"backgroundTag":"schedule-file-not-found","analyzedSha":"756163ed1aa928c8abd629aa2f4904bc5226538c","analyzedAt":"2026-08-21T18:07:39.974Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}