Changeset

3066:cefc375d0929

mod_http_muc_log: Handle errors while loading template file in a more graceful manner
author Kim Alvefur <zash@zash.se>
date Tue, 29 May 2018 05:50:19 +0200
parents 3065:49254b9cc751
children 3067:b01ef74c9fc0
files mod_http_muc_log/mod_http_muc_log.lua
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_muc_log/mod_http_muc_log.lua	Tue May 29 05:04:52 2018 +0200
+++ b/mod_http_muc_log/mod_http_muc_log.lua	Tue May 29 05:50:19 2018 +0200
@@ -32,9 +32,16 @@
 local template;
 do
 	local template_filename = module:get_option_string(module.name .. "_template", module.name .. ".html");
-	local template_file = assert(module:load_resource(template_filename));
-	template = template_file:read("*a");
-	template_file:close();
+	local template_file, err = module:load_resource(template_filename);
+	if template_file then
+		template, err = template_file:read("*a");
+		template_file:close();
+	end
+	if not template then
+		module:log("error", "Error loading template: %s", err);
+		template = render("<h1>mod_{module} could not read the template</h1><p>Tried to open <b>{filename}</b><pre>{error}</pre>",
+			{ module = module.name, filename = template_filename, error = err });
+	end
 end
 
 -- local base_url = module:http_url() .. '/'; -- TODO: Generate links in a smart way