diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-10-07 16:34:03 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-10-07 16:34:03 +0200 |
commit | be149acfdaae06667bc58df467c04c41827b69d0 (patch) | |
tree | 29bd64b3867cf616387d92cb5332eac1737d6ab4 /src/libutil/serialise.cc | |
parent | 27ca87c46a57e1e6603028c1902189b53635d576 (diff) |
Serialize exceptions from the sandbox process to the parent
Fixes #4118.
Diffstat (limited to 'src/libutil/serialise.cc')
-rw-r--r-- | src/libutil/serialise.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index a469a1e73..5c9f6f901 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -266,6 +266,24 @@ Sink & operator << (Sink & sink, const StringSet & s) return sink; } +Sink & operator << (Sink & sink, const Error & ex) +{ + auto info = ex.info(); + sink + << "Error" + << info.level + << info.name + << info.description + << (info.hint ? info.hint->str() : "") + << 0 // FIXME: info.errPos + << info.traces.size(); + for (auto & trace : info.traces) { + sink << 0; // FIXME: trace.pos + sink << trace.hint.str(); + } + return sink; +} + void readPadding(size_t len, Source & source) { @@ -319,6 +337,30 @@ template Paths readStrings(Source & source); template PathSet readStrings(Source & source); +Error readError(Source & source) +{ + auto type = readString(source); + assert(type == "Error"); + ErrorInfo info; + info.level = (Verbosity) readInt(source); + info.name = readString(source); + info.description = readString(source); + auto hint = readString(source); + if (hint != "") info.hint = hintformat(std::move(format("%s") % hint)); + auto havePos = readNum<size_t>(source); + assert(havePos == 0); + auto nrTraces = readNum<size_t>(source); + for (size_t i = 0; i < nrTraces; ++i) { + havePos = readNum<size_t>(source); + assert(havePos == 0); + info.traces.push_back(Trace { + .hint = hintformat(std::move(format("%s") % readString(source))) + }); + } + return Error(std::move(info)); +} + + void StringSink::operator () (const unsigned char * data, size_t len) { static bool warned = false; |