mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 08:16:14 +02:00
nix eval-hydra-jobs: Improve error handling
This commit is contained in:
parent
144bb3ef7d
commit
c6e63065f3
1 changed files with 20 additions and 10 deletions
|
@ -211,6 +211,7 @@ struct CmdEvalHydraJobs : MixJSON, MixDryRun, InstallableCommand
|
||||||
std::set<std::string> todo{""};
|
std::set<std::string> todo{""};
|
||||||
std::set<std::string> active;
|
std::set<std::string> active;
|
||||||
nlohmann::json result;
|
nlohmann::json result;
|
||||||
|
std::exception_ptr exc;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::condition_variable wakeup;
|
std::condition_variable wakeup;
|
||||||
|
@ -239,9 +240,10 @@ struct CmdEvalHydraJobs : MixJSON, MixDryRun, InstallableCommand
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
worker(*to, *from);
|
worker(*to, *from);
|
||||||
} catch (Error & e) {
|
} catch (std::exception & e) {
|
||||||
printError("unexpected worker error: %s", e.msg());
|
nlohmann::json err;
|
||||||
_exit(1);
|
err["error"] = e.what();
|
||||||
|
writeLine(to->get(), err.dump());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ProcessOptions { .allowVfork = false });
|
ProcessOptions { .allowVfork = false });
|
||||||
|
@ -255,8 +257,10 @@ struct CmdEvalHydraJobs : MixJSON, MixDryRun, InstallableCommand
|
||||||
if (s == "restart") {
|
if (s == "restart") {
|
||||||
pid = -1;
|
pid = -1;
|
||||||
continue;
|
continue;
|
||||||
} else if (s != "next")
|
} else if (s != "next") {
|
||||||
throw Error("unexpected worker request: %s", s);
|
auto json = nlohmann::json::parse(s);
|
||||||
|
throw Error("worker error: %s", (std::string) json["error"]);
|
||||||
|
}
|
||||||
|
|
||||||
/* Wait for a job name to become available. */
|
/* Wait for a job name to become available. */
|
||||||
std::string attrPath;
|
std::string attrPath;
|
||||||
|
@ -264,7 +268,7 @@ struct CmdEvalHydraJobs : MixJSON, MixDryRun, InstallableCommand
|
||||||
while (true) {
|
while (true) {
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
auto state(state_.lock());
|
auto state(state_.lock());
|
||||||
if (state->todo.empty() && state->active.empty()) {
|
if ((state->todo.empty() && state->active.empty()) || state->exc) {
|
||||||
writeLine(to.get(), "exit");
|
writeLine(to.get(), "exit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -319,9 +323,10 @@ struct CmdEvalHydraJobs : MixJSON, MixDryRun, InstallableCommand
|
||||||
wakeup.notify_all();
|
wakeup.notify_all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Error & e) {
|
} catch (...) {
|
||||||
printError("unexpected handler thread error: %s", e.msg());
|
auto state(state_.lock());
|
||||||
abort();
|
state->exc = std::current_exception();
|
||||||
|
wakeup.notify_all();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -332,7 +337,12 @@ struct CmdEvalHydraJobs : MixJSON, MixDryRun, InstallableCommand
|
||||||
for (auto & thread : threads)
|
for (auto & thread : threads)
|
||||||
thread.join();
|
thread.join();
|
||||||
|
|
||||||
if (json) std::cout << state_.lock()->result.dump(2) << "\n";
|
auto state(state_.lock());
|
||||||
|
|
||||||
|
if (state->exc)
|
||||||
|
std::rethrow_exception(state->exc);
|
||||||
|
|
||||||
|
if (json) std::cout << state->result.dump(2) << "\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue