From 87fd223be138da58b59a6691a94143bb5aaeda48 Mon Sep 17 00:00:00 2001 From: Richard McGain Date: Mon, 14 Jan 2019 10:13:52 +1100 Subject: [PATCH] Show an error message for the title when it would otherwise result in a 500 --- app/models/shipit/task_definition.rb | 2 ++ test/fixtures/shipit/tasks.yml | 27 +++++++++++++++++++++++++++ test/models/tasks_test.rb | 5 +++++ 3 files changed, 34 insertions(+) diff --git a/app/models/shipit/task_definition.rb b/app/models/shipit/task_definition.rb index a5992f099..7e1a67b3c 100644 --- a/app/models/shipit/task_definition.rb +++ b/app/models/shipit/task_definition.rb @@ -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? diff --git a/test/fixtures/shipit/tasks.yml b/test/fixtures/shipit/tasks.yml index e71f540d3..62a90c874 100644 --- a/test/fixtures/shipit/tasks.yml +++ b/test/fixtures/shipit/tasks.yml @@ -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) %> diff --git a/test/models/tasks_test.rb b/test/models/tasks_test.rb index 9d8b603e1..351045ebd 100644 --- a/test/models/tasks_test.rb +++ b/test/models/tasks_test.rb @@ -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