Mercurial > prosody-hg
comparison util/startup.lua @ 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 | 2041c347c178 |
| children | c1469296190d a874c3f4570a |
comparison
equal
deleted
inserted
replaced
| 14129:6da8b3db84de | 14130:a957cd3ea4eb |
|---|---|
| 95 elseif prosody.process_type == "prosody" then | 95 elseif prosody.process_type == "prosody" then |
| 96 config.set_credential_fallback_mode("error"); | 96 config.set_credential_fallback_mode("error"); |
| 97 else | 97 else |
| 98 config.set_credential_fallback_mode("warn"); | 98 config.set_credential_fallback_mode("warn"); |
| 99 end | 99 end |
| 100 local ok, level, err = config.load(filename); | 100 local ok, level, err, errno = config.load(filename); |
| 101 if not ok then | 101 if not ok then |
| 102 print("\n"); | 102 print("\n"); |
| 103 print("**************************"); | 103 print("**************************"); |
| 104 if level == "parser" then | 104 if level == "parser" then |
| 105 print("A problem occurred while reading the config file "..filename); | 105 print("A problem occurred while reading the config file "..filename); |
| 111 else | 111 else |
| 112 print("Error"..(err_line and (" on line "..err_line) or "")..": "..(err_message or tostring(err))); | 112 print("Error"..(err_line and (" on line "..err_line) or "")..": "..(err_message or tostring(err))); |
| 113 end | 113 end |
| 114 print(""); | 114 print(""); |
| 115 elseif level == "file" then | 115 elseif level == "file" then |
| 116 print("Prosody was unable to find the configuration file."); | 116 local err_kind; |
| 117 print("We looked for: "..filename); | 117 if errno == 2 then |
| 118 print("A sample config file is included in the Prosody download called prosody.cfg.lua.dist"); | 118 err_kind = "find"; |
| 119 print("Copy or rename it to prosody.cfg.lua and edit as necessary."); | 119 elseif errno == 13 then |
| 120 err_kind = "access"; | |
| 121 else err_kind = "open"; | |
| 122 end | |
| 123 print(("Prosody was unable to %s the configuration file:"):format(err_kind)); | |
| 124 print(filename); | |
| 125 print(""); | |
| 126 if err_kind == "access" then | |
| 127 print(prosody.process_type.." does not have permission to open the file."); | |
| 128 print("Try running the command again as a user with permission to read the config file."); | |
| 129 elseif err_kind == "find" then | |
| 130 print("A sample config file is included in the Prosody download called prosody.cfg.lua.dist"); | |
| 131 print("Copy or rename it to "..filename.." and edit as necessary."); | |
| 132 else | |
| 133 print(err); | |
| 134 end | |
| 135 print(""); | |
| 120 end | 136 end |
| 121 print("More help on configuring Prosody can be found at https://prosody.im/doc/configure"); | 137 print("More help on configuring Prosody can be found at https://prosody.im/doc/configure"); |
| 122 print("Good luck!"); | 138 print("Good luck!"); |
| 123 print("**************************"); | 139 print("**************************"); |
| 124 print(""); | 140 print(""); |
