Commit e9bd2f8e authored by Stanislav Bohm's avatar Stanislav Bohm

ENH: Reporting non-zero exit code from loom/run task

parent 8a1d192c
......@@ -8,6 +8,7 @@
#include "loomrun.pb.h"
#include <sstream>
#include <fstream>
using namespace loom;
......@@ -108,7 +109,8 @@ void RunTask::start(DataVector &inputs)
if (stderr_fd < 0) {
log_errno_abort("open +err:");
}
stdio[2].flags = UV_IGNORE;
stdio[2].flags = UV_INHERIT_FD;
stdio[2].data.fd = stderr_fd;
int r;
......@@ -147,7 +149,25 @@ void RunTask::_on_close(uv_handle_t *handle)
{
RunTask *task = static_cast<RunTask*>(handle->data);
llog->debug("Process id={} finished (exit_status={})", task->get_id(), task->exit_status);
assert(task->exit_status == 0);
if (task->exit_status) {
std::stringstream s;
s << "Program terminated with status " << task->exit_status;
s << "\nStderr:\n";
std::ifstream err(task->get_path("+err").c_str());
assert(err.is_open());
int max_buffer_size = 128 * 1024;
auto buffer = std::make_unique<char[]>(max_buffer_size);
err.read(buffer.get(), max_buffer_size);
s.write(buffer.get(), err.gcount());
if (err.gcount() == max_buffer_size) {
s << "\n ... stderr truncated by Loom";
}
task->fail(s.str());
return;
}
loomrun::Run msg;
msg.ParseFromString(task->task->get_config());
std::unique_ptr<Data> result;
......
from loomenv import loom_env, LOOM_TESTPROG, LOOM_TEST_DATA_DIR # noqa
from datetime import datetime
import os
import client
import pytest
......@@ -15,3 +13,12 @@ def test_invalid_program(loom_env):
with pytest.raises(client.TaskFailed):
loom_env.submit(p, a)
def test_program_failed(loom_env):
loom_env.start(1)
p = loom_env.plan()
a = p.task_run("ls /non-existing-dictionary")
with pytest.raises(client.TaskFailed):
loom_env.submit(p, a)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment