diff --git a/templates/unitfile.erb b/templates/unitfile.erb
index 5f704fb32093fe6c322d85f42dfe4fd975b475c9..1aea7da3bd92ce6c395c5c83fbac7863b59a1b93 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 %>