Compare commits

...

1 commit

Author SHA1 Message Date
Nicolas Lenz e6e97811de
feat: add try-catch to some usages of readLine 2024-08-21 10:25:35 +02:00
2 changed files with 16 additions and 2 deletions

View file

@ -558,7 +558,14 @@ std::optional<char> ProgressBar::ask(std::string_view msg)
auto state(state_.lock());
if (state->paused > 0 || !isatty(STDIN_FILENO)) return {};
std::cerr << fmt("\r\e[K%s ", msg);
auto s = trim(readLine(STDIN_FILENO));
auto s = [&]() {
try {
return trim(readLine(STDIN_FILENO));
} catch (Error & e) {
e.addTrace({}, "while trying to read from STDIN to ask something");
throw;
}
}();
if (s.size() != 1) return {};
draw(*state, {});
return s[0];

View file

@ -930,7 +930,14 @@ Pid LinuxLocalDerivationGoal::startChild(std::function<void()> openSlave)
userNamespaceSync.writeSide.reset();
});
auto ss = tokenizeString<std::vector<std::string>>(readLine(sendPid.readSide.get()));
auto ss = [&]() {
try {
return tokenizeString<std::vector<std::string>>(readLine(sendPid.readSide.get()));
} catch (Error & e) {
e.addTrace({}, "while... how am I supposed to know?");
throw;
}
}();
assert(ss.size() == 1);
Pid pid = Pid{string2Int<pid_t>(ss[0]).value()};