comparison util/prosodyctl/shell.lua @ 14016:1df1782ccdfe

prosodyctl shell: Improve process exit codes This fixes a bug introduced in 3326c8a29a86 where prosodyctl shell would always exit with non-zero error codes, even on success. Now it will exit with 0 for success, or 1 if any errors were printed. It also updates the other exit codes in the shell command to help distinguish between different error cases. These are based on the sysexits.h codes, although it is not recommended to rely on that interface.
author Matthew Wild <mwild1@gmail.com>
date Fri, 19 Dec 2025 15:32:26 +0000
parents 3326c8a29a86
children 3c2bfa6a69df
comparison
equal deleted inserted replaced
14015:42e035cd3322 14016:1df1782ccdfe
80 if err == "param-not-found" then 80 if err == "param-not-found" then
81 print("Unknown command-line option: "..tostring(where)); 81 print("Unknown command-line option: "..tostring(where));
82 elseif err == "missing-value" then 82 elseif err == "missing-value" then
83 print("Expected a value to follow command-line option: "..where); 83 print("Expected a value to follow command-line option: "..where);
84 end 84 end
85 os.exit(1); 85 os.exit(64);
86 end 86 end
87 87
88 if arg[1] then 88 if arg[1] then
89 if arg[2] then 89 if arg[2] then
90 arg[1] = ("{"..string.rep("%q", #arg, ", ").."}"):format(table.unpack(arg, 1, #arg)); 90 arg[1] = ("{"..string.rep("%q", #arg, ", ").."}"):format(table.unpack(arg, 1, #arg));
98 local errors = 0; -- TODO This is weird, but works for now. 98 local errors = 0; -- TODO This is weird, but works for now.
99 client.events.add_handler("received", function(stanza) 99 client.events.add_handler("received", function(stanza)
100 if stanza.name == "repl-output" or stanza.name == "repl-result" then 100 if stanza.name == "repl-output" or stanza.name == "repl-result" then
101 local dest = io.stdout; 101 local dest = io.stdout;
102 if stanza.name == "repl-result" or stanza.attr.type == "error" then 102 if stanza.name == "repl-result" or stanza.attr.type == "error" then
103 errors = errors + 1; 103 if stanza.attr.type == "error" then
104 errors = errors + 1;
105 end
104 dest = io.stderr; 106 dest = io.stderr;
105 end 107 end
106 if stanza.attr.eol == "0" then 108 if stanza.attr.eol == "0" then
107 dest:write(stanza:get_text()); 109 dest:write(stanza:get_text());
108 else 110 else
109 dest:write(stanza:get_text(), "\n"); 111 dest:write(stanza:get_text(), "\n");
110 end 112 end
111 end 113 end
112 if stanza.name == "repl-result" then 114 if stanza.name == "repl-result" then
113 os.exit(errors); 115 os.exit(errors > 0 and 1 or 0);
114 end 116 end
115 return true; 117 return true;
116 end, 1); 118 end, 1);
117 end 119 end
118 120
139 id = stanza.attr.id; 141 id = stanza.attr.id;
140 status = password and "submit" or "cancel"; 142 status = password and "submit" or "cancel";
141 }):text(password or "")); 143 }):text(password or ""));
142 else 144 else
143 io.stderr:write("Internal error - unexpected input request type "..tostring(stanza.attr.type).."\n"); 145 io.stderr:write("Internal error - unexpected input request type "..tostring(stanza.attr.type).."\n");
144 os.exit(1); 146 os.exit(76);
145 end 147 end
146 return true; 148 return true;
147 end, 2); 149 end, 2);
148 150
149 151
172 print("** version is up to date."); 174 print("** version is up to date.");
173 else 175 else
174 print("** Unable to connect to server - is it running? Is mod_admin_shell enabled?"); 176 print("** Unable to connect to server - is it running? Is mod_admin_shell enabled?");
175 print("** Connection error: "..err); 177 print("** Connection error: "..err);
176 end 178 end
177 os.exit(1); 179 os.exit(69);
178 end 180 end
179 server.loop(); 181 server.loop();
180 end 182 end
181 183
182 return { 184 return {