Skip to content

Fall back to current task when no top-level task is set#328

Merged
OdenTakashi merged 1 commit intodrwl:mainfrom
jordan-brough:top-level-tasks-improvement
Apr 25, 2026
Merged

Fall back to current task when no top-level task is set#328
OdenTakashi merged 1 commit intodrwl:mainfrom
jordan-brough:top-level-tasks-improvement

Conversation

@jordan-brough
Copy link
Copy Markdown
Contributor

When a task is invoked programmatically Rake's CLI parser never runs so top_level_tasks is empty.
Fall back to the current task name in that case.

Example:

$ rails runner '
    require "rake"
    Rails.application.load_tasks
    Rake::Task["db:migrate"].invoke
  '

Results in:

.../ruby/3.4.8/lib/ruby/gems/3.4.0/gems/rake-13.4.2/lib/rake/task_manager.rb:59:in 'Rake::TaskManager#[]':
  Don't know how to build task '' (See the list of available tasks with `rake --tasks`)
  (RuntimeError)

without this fix.

When a task is invoked programmatically Rake's CLI parser never runs so `top_level_tasks` is empty.
Fall back to the current task name in that case.

Example:
```ruby
$ rails runner '
    require "rake"
    Rails.application.load_tasks
    Rake::Task["db:migrate"].invoke
  '
```

Results in:
```
.../ruby/3.4.8/lib/ruby/gems/3.4.0/gems/rake-13.4.2/lib/rake/task_manager.rb:59:in 'Rake::TaskManager#[]':
  Don't know how to build task '' (See the list of available tasks with `rake --tasks`)
  (RuntimeError)
```
without this fix.
Copy link
Copy Markdown
Collaborator

@OdenTakashi OdenTakashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this.

@OdenTakashi OdenTakashi merged commit c6d36a0 into drwl:main Apr 25, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants