Print a more helpful message if the daemon crashes

Instead of

   error: unexpected end-of-file

you now get

   error: Nix daemon disconnected unexpectedly (maybe it crashed?)
This commit is contained in:
Eelco Dolstra 2024-01-17 22:19:51 +01:00
parent b5ed36e663
commit a3cf27ca47
3 changed files with 5 additions and 3 deletions

View File

@ -67,6 +67,7 @@ void RemoteStore::initConnection(Connection & conn)
{ {
/* Send the magic greeting, check for the reply. */ /* Send the magic greeting, check for the reply. */
try { try {
conn.from.endOfFileError = "Nix daemon disconnected unexpectedly (maybe it crashed?)";
conn.to << WORKER_MAGIC_1; conn.to << WORKER_MAGIC_1;
conn.to.flush(); conn.to.flush();
StringSink saved; StringSink saved;

View File

@ -132,7 +132,7 @@ size_t FdSource::readUnbuffered(char * data, size_t len)
n = ::read(fd, data, len); n = ::read(fd, data, len);
} while (n == -1 && errno == EINTR); } while (n == -1 && errno == EINTR);
if (n == -1) { _good = false; throw SysError("reading from file"); } if (n == -1) { _good = false; throw SysError("reading from file"); }
if (n == 0) { _good = false; throw EndOfFile("unexpected end-of-file"); } if (n == 0) { _good = false; throw EndOfFile(endOfFileError); }
read += n; read += n;
return n; return n;
} }

View File

@ -153,12 +153,13 @@ struct FdSource : BufferedSource
{ {
int fd; int fd;
size_t read = 0; size_t read = 0;
std::string endOfFileError{"unexpected end-of-file"};
FdSource() : fd(-1) { } FdSource() : fd(-1) { }
FdSource(int fd) : fd(fd) { } FdSource(int fd) : fd(fd) { }
FdSource(FdSource&&) = default; FdSource(FdSource &&) = default;
FdSource& operator=(FdSource && s) FdSource & operator=(FdSource && s)
{ {
fd = s.fd; fd = s.fd;
s.fd = -1; s.fd = -1;