From 3bd974d3caf27aacfa71b593332b665f7e9361ae Mon Sep 17 00:00:00 2001 From: Thomas Bellman <bellman@lysator.liu.se> Date: Mon, 4 Oct 2021 22:35:25 +0200 Subject: [PATCH] Better error messages from unitfile.erb template. Have the error messages that unitfile.erb can raise include reference to the resource (type and title) causing the error, so users can find where they made the error. --- templates/unitfile.erb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/templates/unitfile.erb b/templates/unitfile.erb index 5f704fb..1aea7da 100644 --- a/templates/unitfile.erb +++ b/templates/unitfile.erb @@ -2,7 +2,8 @@ # Copyright © 2021 Thomas Bellman, Linköping, Sweden # Licensed under the GNU LGPL v3+; see the README file for more information. -%> -<% comment_lines = [@comment].flatten.join("\n").split("\n") +<% resource_ref = "Systemd::%s[%s]" % [ @systemd_resource_type, @title, ] + comment_lines = [@comment].flatten.join("\n").split("\n") if comment_lines.length() > 0 comment_lines.each do |cline| -%> @@ -18,10 +19,11 @@ -%> <%= optname %>= <% elsif @systemd_resource_type == 'Unit' - raise(Puppet::ParseError, "Bad option name, ``#{optname}''") + raise(Puppet::ParseError, + "#{resource_ref}: Bad option name, ``#{optname}''") else raise(Puppet::ParseError, - 'Internal error: $systemd_resource_type bad value') + "#{resource_ref}: Internal error: bad value for $systemd_resource_type, ``#{systemd_resource_type}''") -%> <% end -%> <% end -%> @@ -30,4 +32,4 @@ <% end -%> <% end %> <% end -%> -# Managed by Puppet: Systemd::<%= @systemd_resource_type %>[<%= @title %>] +# Managed by Puppet: <%= resource_ref %> -- GitLab