changeset 4686:76af816739f3

mod_debug_omemo: Fix traceback in case of zero devices Turns out ipairs(nil) in Lua 5.4 does not throw until the first iterator.
author Kim Alvefur <zash@zash.se>
date Mon, 13 Sep 2021 21:47:01 +0200
parents 07b6f444bafb
children 41ddb782320c
files mod_debug_omemo/mod_debug_omemo.lua mod_debug_omemo/view.tpl.html
diffstat 2 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mod_debug_omemo/mod_debug_omemo.lua	Mon Sep 13 21:45:20 2021 +0200
+++ b/mod_debug_omemo/mod_debug_omemo.lua	Mon Sep 13 21:47:01 2021 +0200
@@ -167,12 +167,16 @@
 	};
 
 	data.omemo.devices = {};
-	for _, device_info in ipairs(user_omemo_status.devices) do
-		data.omemo.devices[("%d"):format(device_info.id)] = {
-			status = device_info.valid and "OK" or "Problem";
-			bundle = device_info.have_bundle and "Published" or "Missing";
-			access_model = access_model_text[device_info.bundle_config and device_info.bundle_config.access_model or nil];
-		};
+	if user_omemo_status.devices then
+		for _, device_info in ipairs(user_omemo_status.devices) do
+			data.omemo.devices[("%d"):format(device_info.id)] = {
+				status = device_info.valid and "OK" or "Problem";
+				bundle = device_info.have_bundle and "Published" or "Missing";
+				access_model = access_model_text[device_info.bundle_config and device_info.bundle_config.access_model or nil];
+			};
+		end
+	else
+		data.omemo.devices[false] = { status = "No devices", };
 	end
 
 	event.response.headers.content_type = "text/html; charset=utf-8";
--- a/mod_debug_omemo/view.tpl.html	Mon Sep 13 21:45:20 2021 +0200
+++ b/mod_debug_omemo/view.tpl.html	Mon Sep 13 21:47:01 2021 +0200
@@ -211,10 +211,10 @@
 			<th>Access</th>
 		</tr>
 		{omemo.devices%<tr>
-			<td>{idx}</td>
-			<td>{item.status}</td>
-			<td>{item.bundle}</td>
-			<td>{item.access_model}</td>
+			<td>{idx?<i>N/A</i>}</td>
+			<td>{item.status?<i>N/A</i>}</td>
+			<td>{item.bundle?<i>N/A</i>}</td>
+			<td>{item.access_model?<i>N/A</i>}</td>
 		</tr>}
 	</table>
 </div>