hydra-eval-jobs: Identify unexpected errors in handling aggregate jobs

The vague "[json.exception.type_error.302] type must be string, but is null"
is **absolutely** unhelpful in the way Hydra currently handles it on
evaluation.

This is handling *unexpected* errors only; the following commit will
handle the specific instance of the previously mentioned error.
This commit is contained in:
Samuel Dionne-Riel 2020-10-25 18:50:54 -04:00
parent be709d450b
commit 68e689cace

View file

@ -442,45 +442,57 @@ int main(int argc, char * * argv)
for (auto i = state->jobs.begin(); i != state->jobs.end(); ++i) { for (auto i = state->jobs.begin(); i != state->jobs.end(); ++i) {
auto jobName = i.key(); auto jobName = i.key();
auto & job = i.value(); auto & job = i.value();
// For the error message
std::string lastTriedJobName = i.key();
auto named = job.find("namedConstituents"); auto named = job.find("namedConstituents");
if (named == job.end()) continue; if (named == job.end()) continue;
if (myArgs.dryRun) { try {
for (std::string jobName2 : *named) { if (myArgs.dryRun) {
auto job2 = state->jobs.find(jobName2); for (std::string jobName2 : *named) {
if (job2 == state->jobs.end()) lastTriedJobName = jobName2;
throw Error("aggregate job '%s' references non-existent job '%s'", jobName, jobName2); auto job2 = state->jobs.find(jobName2);
std::string drvPath2 = (*job2)["drvPath"]; if (job2 == state->jobs.end())
job["constituents"].push_back(drvPath2); throw Error("aggregate job '%s' references non-existent job '%s'", jobName, jobName2);
std::string drvPath2 = (*job2)["drvPath"];
job["constituents"].push_back(drvPath2);
}
} else {
auto drvPath = store->parseStorePath((std::string) job["drvPath"]);
auto drv = store->readDerivation(drvPath);
for (std::string jobName2 : *named) {
lastTriedJobName = jobName2;
auto job2 = state->jobs.find(jobName2);
if (job2 == state->jobs.end())
throw Error("aggregate job '%s' references non-existent job '%s'", jobName, jobName2);
auto drvPath2 = store->parseStorePath((std::string) (*job2)["drvPath"]);
auto drv2 = store->readDerivation(drvPath2);
job["constituents"].push_back(store->printStorePath(drvPath2));
drv.inputDrvs[drvPath2] = {drv2.outputs.begin()->first};
}
std::string drvName(drvPath.name());
assert(hasSuffix(drvName, drvExtension));
drvName.resize(drvName.size() - drvExtension.size());
auto h = std::get<Hash>(hashDerivationModulo(*store, drv, true));
auto outPath = store->makeOutputPath("out", h, drvName);
drv.env["out"] = store->printStorePath(outPath);
drv.outputs.insert_or_assign("out", DerivationOutput { .output = DerivationOutputInputAddressed { .path = outPath } });
auto newDrvPath = store->printStorePath(writeDerivation(*store, drv));
debug("rewrote aggregate derivation %s -> %s", store->printStorePath(drvPath), newDrvPath);
job["drvPath"] = newDrvPath;
job["outputs"]["out"] = store->printStorePath(outPath);
} }
} else { } catch (std::exception & e) {
auto drvPath = store->parseStorePath((std::string) job["drvPath"]); // Print more information to help debugging.
auto drv = store->readDerivation(drvPath); printError("Unexpected error in hydra-eval-jobs when handling job '%s', when producing aggregate job '%s':", lastTriedJobName, jobName);
for (std::string jobName2 : *named) { // And throw the original exception!
auto job2 = state->jobs.find(jobName2); throw;
if (job2 == state->jobs.end())
throw Error("aggregate job '%s' references non-existent job '%s'", jobName, jobName2);
auto drvPath2 = store->parseStorePath((std::string) (*job2)["drvPath"]);
auto drv2 = store->readDerivation(drvPath2);
job["constituents"].push_back(store->printStorePath(drvPath2));
drv.inputDrvs[drvPath2] = {drv2.outputs.begin()->first};
}
std::string drvName(drvPath.name());
assert(hasSuffix(drvName, drvExtension));
drvName.resize(drvName.size() - drvExtension.size());
auto h = std::get<Hash>(hashDerivationModulo(*store, drv, true));
auto outPath = store->makeOutputPath("out", h, drvName);
drv.env["out"] = store->printStorePath(outPath);
drv.outputs.insert_or_assign("out", DerivationOutput { .output = DerivationOutputInputAddressed { .path = outPath } });
auto newDrvPath = store->printStorePath(writeDerivation(*store, drv));
debug("rewrote aggregate derivation %s -> %s", store->printStorePath(drvPath), newDrvPath);
job["drvPath"] = newDrvPath;
job["outputs"]["out"] = store->printStorePath(outPath);
} }
job.erase("namedConstituents"); job.erase("namedConstituents");