Skip to content

Commit

Permalink
Show an error message for the title when it would otherwise result in…
Browse files Browse the repository at this point in the history
… a 500
  • Loading branch information
Richard McGain committed Feb 5, 2019
1 parent e6cb71b commit 87fd223
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/shipit/task_definition.rb
Expand Up @@ -35,6 +35,8 @@ def render_title(env)
else
action
end
rescue KeyError
"This task (title: #{@title}) cannot be shown due to an incorrect variable name. Check your shipit.yml file"
end

def allow_concurrency?
Expand Down
27 changes: 27 additions & 0 deletions test/fixtures/shipit/tasks.yml
Expand Up @@ -209,3 +209,30 @@ canaries_running:
created_at: <%= (60 - 7).minutes.ago.to_s(:db) %>
started_at: <%= (60 - 7).minutes.ago.to_s(:db) %>
ended_at: <%= (60 - 10).minutes.ago.to_s(:db) %>

shipit_with_title_parsing_issue:
id: 105
user: walrus
since_commit_id: 2 # second
until_commit_id: 2 # second
type: Shipit::Task
stack: shipit
status: success
definition: >
{
"id": "bad-title",
"action": "Task with bad title",
"title": "Using the %{WRONG_VARIABLE_NAME}",
"description": "This task uses the wrong variable name",
"variables": [
{"name": "VARIABLE_NAME", "title": "Any old variable"}
],
"steps": [
"does not matter"
]
}
env:
POD_ID: "12"
created_at: <%= (60 - 3).minutes.ago.to_s(:db) %>
started_at: <%= (60 - 3).minutes.ago.to_s(:db) %>
ended_at: <%= (60 - 4).minutes.ago.to_s(:db) %>
5 changes: 5 additions & 0 deletions test/models/tasks_test.rb
Expand Up @@ -12,5 +12,10 @@ class TasksTest < ActiveSupport::TestCase
task = shipit_tasks(:shipit_restart)
assert_equal 'Restart application', task.title
end

test '#title returns an error message when the title raises an error' do
task = shipit_tasks(:shipit_with_title_parsing_issue)
assert_equal 'This task (title: Using the %{WRONG_VARIABLE_NAME}) cannot be shown due to an incorrect variable name. Check your shipit.yml file', task.title
end
end
end

0 comments on commit 87fd223

Please sign in to comment.