Improve 'coroutine has finished' error message
This commit is contained in:
parent
6317c65937
commit
ebe3d2d370
3 changed files with 16 additions and 7 deletions
|
@ -609,6 +609,8 @@ void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
|
||||||
act.progress(total, info->narSize);
|
act.progress(total, info->narSize);
|
||||||
});
|
});
|
||||||
srcStore->narFromPath({storePath}, wrapperSink);
|
srcStore->narFromPath({storePath}, wrapperSink);
|
||||||
|
}, [&]() {
|
||||||
|
throw EndOfFile("NAR for '%s' fetched from '%s' is incomplete", storePath, srcStore->getUri());
|
||||||
});
|
});
|
||||||
|
|
||||||
dstStore->addToStore(*info, *source, repair, checkSigs);
|
dstStore->addToStore(*info, *source, repair, checkSigs);
|
||||||
|
|
|
@ -161,16 +161,20 @@ size_t StringSource::read(unsigned char * data, size_t len)
|
||||||
#error Coroutines are broken in this version of Boost!
|
#error Coroutines are broken in this version of Boost!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::unique_ptr<Source> sinkToSource(std::function<void(Sink &)> fun)
|
std::unique_ptr<Source> sinkToSource(
|
||||||
|
std::function<void(Sink &)> fun,
|
||||||
|
std::function<void()> eof)
|
||||||
{
|
{
|
||||||
struct SinkToSource : Source
|
struct SinkToSource : Source
|
||||||
{
|
{
|
||||||
typedef boost::coroutines2::coroutine<std::string> coro_t;
|
typedef boost::coroutines2::coroutine<std::string> coro_t;
|
||||||
|
|
||||||
|
std::function<void()> eof;
|
||||||
coro_t::pull_type coro;
|
coro_t::pull_type coro;
|
||||||
|
|
||||||
SinkToSource(std::function<void(Sink &)> fun)
|
SinkToSource(std::function<void(Sink &)> fun, std::function<void()> eof)
|
||||||
: coro([&](coro_t::push_type & yield) {
|
: eof(eof)
|
||||||
|
, coro([&](coro_t::push_type & yield) {
|
||||||
LambdaSink sink([&](const unsigned char * data, size_t len) {
|
LambdaSink sink([&](const unsigned char * data, size_t len) {
|
||||||
if (len) yield(std::string((const char *) data, len));
|
if (len) yield(std::string((const char *) data, len));
|
||||||
});
|
});
|
||||||
|
@ -184,8 +188,7 @@ std::unique_ptr<Source> sinkToSource(std::function<void(Sink &)> fun)
|
||||||
|
|
||||||
size_t read(unsigned char * data, size_t len) override
|
size_t read(unsigned char * data, size_t len) override
|
||||||
{
|
{
|
||||||
if (!coro)
|
if (!coro) { eof(); abort(); }
|
||||||
throw EndOfFile("coroutine has finished");
|
|
||||||
|
|
||||||
if (pos == cur.size()) {
|
if (pos == cur.size()) {
|
||||||
if (!cur.empty()) coro();
|
if (!cur.empty()) coro();
|
||||||
|
@ -201,7 +204,7 @@ std::unique_ptr<Source> sinkToSource(std::function<void(Sink &)> fun)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return std::make_unique<SinkToSource>(fun);
|
return std::make_unique<SinkToSource>(fun, eof);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,11 @@ struct LambdaSource : Source
|
||||||
|
|
||||||
/* Convert a function that feeds data into a Sink into a Source. The
|
/* Convert a function that feeds data into a Sink into a Source. The
|
||||||
Source executes the function as a coroutine. */
|
Source executes the function as a coroutine. */
|
||||||
std::unique_ptr<Source> sinkToSource(std::function<void(Sink &)> fun);
|
std::unique_ptr<Source> sinkToSource(
|
||||||
|
std::function<void(Sink &)> fun,
|
||||||
|
std::function<void()> eof = []() {
|
||||||
|
throw EndOfFile("coroutine has finished");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
void writePadding(size_t len, Sink & sink);
|
void writePadding(size_t len, Sink & sink);
|
||||||
|
|
Loading…
Reference in a new issue