changeset 14130:a957cd3ea4eb 13.0

util.startup: Improve error message when failing to load config file The current error text always implied that the file is missing, but it could also be a permissions issue, or something else. Now it will handle those two cases, and show the error from the system otherwise.
author Matthew Wild <mwild1@gmail.com>
date Thu, 16 Apr 2026 18:50:23 +0100
parents 6da8b3db84de
children 6c7549964d4d
files util/startup.lua
diffstat 1 files changed, 21 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/util/startup.lua	Thu Apr 16 18:49:04 2026 +0100
+++ b/util/startup.lua	Thu Apr 16 18:50:23 2026 +0100
@@ -97,7 +97,7 @@
 	else
 		config.set_credential_fallback_mode("warn");
 	end
-	local ok, level, err = config.load(filename);
+	local ok, level, err, errno = config.load(filename);
 	if not ok then
 		print("\n");
 		print("**************************");
@@ -113,10 +113,26 @@
 			end
 			print("");
 		elseif level == "file" then
-			print("Prosody was unable to find the configuration file.");
-			print("We looked for: "..filename);
-			print("A sample config file is included in the Prosody download called prosody.cfg.lua.dist");
-			print("Copy or rename it to prosody.cfg.lua and edit as necessary.");
+			local err_kind;
+			if errno == 2 then
+				err_kind = "find";
+			elseif errno == 13 then
+				err_kind = "access";
+			else err_kind = "open";
+			end
+			print(("Prosody was unable to %s the configuration file:"):format(err_kind));
+			print(filename);
+			print("");
+			if err_kind == "access" then
+				print(prosody.process_type.." does not have permission to open the file.");
+				print("Try running the command again as a user with permission to read the config file.");
+			elseif err_kind == "find" then
+				print("A sample config file is included in the Prosody download called prosody.cfg.lua.dist");
+				print("Copy or rename it to "..filename.." and edit as necessary.");
+			else
+				print(err);
+			end
+			print("");
 		end
 		print("More help on configuring Prosody can be found at https://prosody.im/doc/configure");
 		print("Good luck!");