RemoteStore: Propagate InvalidPath exceptions from the daemon

This commit is contained in:
Eelco Dolstra 2016-04-20 15:28:07 +02:00
parent c0c4ddcd9c
commit ddea253ff8
3 changed files with 28 additions and 9 deletions

View file

@ -243,7 +243,18 @@ std::shared_ptr<ValidPathInfo> RemoteStore::queryPathInfoUncached(const Path & p
{ {
auto conn(connections->get()); auto conn(connections->get());
conn->to << wopQueryPathInfo << path; conn->to << wopQueryPathInfo << path;
conn->processStderr(); try {
conn->processStderr();
} catch (Error & e) {
// Ugly backwards compatibility hack.
if (e.msg().find("is not valid") != std::string::npos)
throw InvalidPath(e.what());
throw;
}
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 17) {
bool valid = readInt(conn->from) != 0;
if (!valid) throw InvalidPath(format("path %s is not valid") % path);
}
auto info = std::make_shared<ValidPathInfo>(); auto info = std::make_shared<ValidPathInfo>();
info->path = path; info->path = path;
info->deriver = readString(conn->from); info->deriver = readString(conn->from);

View file

@ -6,7 +6,7 @@ namespace nix {
#define WORKER_MAGIC_1 0x6e697863 #define WORKER_MAGIC_1 0x6e697863
#define WORKER_MAGIC_2 0x6478696f #define WORKER_MAGIC_2 0x6478696f
#define PROTOCOL_VERSION 0x110 #define PROTOCOL_VERSION 0x111
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00) #define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff) #define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)

View file

@ -495,15 +495,23 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
case wopQueryPathInfo: { case wopQueryPathInfo: {
Path path = readStorePath(from); Path path = readStorePath(from);
std::shared_ptr<const ValidPathInfo> info;
startWork(); startWork();
auto info = store->queryPathInfo(path); try {
stopWork(); info = store->queryPathInfo(path);
to << info->deriver << printHash(info->narHash) << info->references } catch (InvalidPath &) {
<< info->registrationTime << info->narSize; if (GET_PROTOCOL_MINOR(clientVersion) < 17) throw;
if (GET_PROTOCOL_MINOR(clientVersion) >= 16) {
to << info->ultimate
<< info->sigs;
} }
stopWork();
if (info) {
to << 1 << info->deriver << printHash(info->narHash) << info->references
<< info->registrationTime << info->narSize;
if (GET_PROTOCOL_MINOR(clientVersion) >= 16) {
to << info->ultimate
<< info->sigs;
}
} else
to << 0;
break; break;
} }