Commit 5f422f65 authored by Kenton Varda's avatar Kenton Varda

serialize-async should throw DISCONNECTED on premature EOF.

This isn't related to JSON-RPC but is a fix needed for the Ekam language server.
parent 899e7cfc
......@@ -71,9 +71,8 @@ kj::Promise<bool> AsyncMessageReader::read(kj::AsyncInputStream& inputStream,
return false;
} else if (n < sizeof(firstWord)) {
// EOF in first word.
KJ_FAIL_REQUIRE("Premature EOF.") {
return false;
}
kj::throwRecoverableException(KJ_EXCEPTION(DISCONNECTED, "Premature EOF."));
return false;
}
return readAfterFirstWord(inputStream, scratchSpace).then([]() { return true; });
......@@ -153,7 +152,9 @@ kj::Promise<kj::Own<MessageReader>> readMessage(
auto reader = kj::heap<AsyncMessageReader>(options);
auto promise = reader->read(input, scratchSpace);
return promise.then(kj::mvCapture(reader, [](kj::Own<MessageReader>&& reader, bool success) {
KJ_REQUIRE(success, "Premature EOF.") { break; }
if (!success) {
kj::throwRecoverableException(KJ_EXCEPTION(DISCONNECTED, "Premature EOF."));
}
return kj::mv(reader);
}));
}
......
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