From 9d13669b595a2994fc3cf8d88a8ec899a7d70cbb Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Fri, 2 Feb 2024 10:31:44 +0100 Subject: [PATCH] Display error message if lookup fails #264 --- app/controllers/lookups_controller.rb | 4 ++++ app/views/lookups/error.html.erb | 5 +++++ .../files/puppet/environments/lookup_tests/data/common.yaml | 3 +++ .../lookup_tests/data/nodes/lookup.betadots.training.yaml | 2 ++ 4 files changed, 14 insertions(+) create mode 100644 app/views/lookups/error.html.erb diff --git a/app/controllers/lookups_controller.rb b/app/controllers/lookups_controller.rb index a5dd82e4..66dbacd5 100644 --- a/app/controllers/lookups_controller.rb +++ b/app/controllers/lookups_controller.rb @@ -5,6 +5,10 @@ class LookupsController < ApplicationController def show @result = @key.lookup(@node) + rescue Hdm::Error => error + @error = error + + render action: "error" end private diff --git a/app/views/lookups/error.html.erb b/app/views/lookups/error.html.erb new file mode 100644 index 00000000..9df4a8e7 --- /dev/null +++ b/app/views/lookups/error.html.erb @@ -0,0 +1,5 @@ +<%= turbo_frame_tag "lookup-result-frame" do %> +

+ <%= @error.message %> +

+<% end %> diff --git a/test/fixtures/files/puppet/environments/lookup_tests/data/common.yaml b/test/fixtures/files/puppet/environments/lookup_tests/data/common.yaml index 636779ce..5f46d2d2 100644 --- a/test/fixtures/files/puppet/environments/lookup_tests/data/common.yaml +++ b/test/fixtures/files/puppet/environments/lookup_tests/data/common.yaml @@ -18,6 +18,7 @@ hdm_nested_hash: nested_hash: integer: 32 added_by_common: common +hdm_mixed_types: 42 lookup_options: '^hdm_duplicates': merge: hash @@ -26,4 +27,6 @@ lookup_options: hash_syntax: merge: strategy: deep + hdm_mixed_types: + merge: deep diff --git a/test/fixtures/files/puppet/environments/lookup_tests/data/nodes/lookup.betadots.training.yaml b/test/fixtures/files/puppet/environments/lookup_tests/data/nodes/lookup.betadots.training.yaml index af1d6d20..fefa500d 100644 --- a/test/fixtures/files/puppet/environments/lookup_tests/data/nodes/lookup.betadots.training.yaml +++ b/test/fixtures/files/puppet/environments/lookup_tests/data/nodes/lookup.betadots.training.yaml @@ -14,3 +14,5 @@ hdm_nested_hash: origin: node nested_hash: integer: 5 +hdm_mixed_types: + from_node: 23