better error messages.

This commit is contained in:
Your Name 2025-04-26 22:06:57 +12:00
parent d95500f679
commit 71cb39d82e
3 changed files with 13 additions and 3 deletions

View File

@ -211,7 +211,7 @@ int main(int argc, char* argv[]) {
for (const auto& service_info : servicelist) {
dropshell::service_runner runner(server_name, service_info.service_name);
if (!runner.isValid) {
if (!runner.isValid()) {
std::cerr << "Error: Failed to initialize service" << std::endl;
return 1;
}

View File

@ -32,7 +32,7 @@ typedef struct ServiceStatus {
class service_runner {
public:
service_runner(const std::string& server_name, const std::string& service_name);
bool isValid;
bool isValid() const { return mValid; }
// run a command over ssh, using the credentials from server.env (via server_env.hpp)
// first check that the command corresponds to a valid .sh file in the service directory

View File

@ -67,7 +67,17 @@ ServiceInfo get_service_info(const std::string &server_name, const std::string &
std::string local_service_env_path = get_local_service_env_path(server_name, service_name);
envmanager env(local_service_env_path);
if (!env.load()) {
std::cerr << "Error: service.env missing from " << local_service_env_path << std::endl;
if (std::filesystem::exists(get_local_service_path(server_name, service_name)))
std::cerr << "Error: service malformed - service.env missing from " << local_service_env_path << std::endl;
else
{
template_info tinfo;
get_template_info(service_name, tinfo);
std::string template_name = service_name;
if (tinfo.local_template_path.empty())
template_name = "TEMPLATE";
std::cerr << "Error: you need to create that service first, with: dropshell create-service " << server_name << " "<<template_name<<" " << service_name << std::endl;
}
return ServiceInfo();
}
service.template_name = env.get_variable("TEMPLATE");