From c770a2422a47526d5eb336af6af4292df68dad2b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 1 Aug 2012 11:19:24 -0400 Subject: Report substituter errors to clients of the Nix daemon --- src/libutil/util.cc | 9 ++++++++- src/libutil/util.hh | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/libutil') diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 689fc543af..086574058a 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -253,7 +253,7 @@ string readLine(int fd) if (errno != EINTR) throw SysError("reading a line"); } else if (rd == 0) - throw Error("unexpected EOF reading a line"); + throw EndOfFile("unexpected EOF reading a line"); else { if (ch == '\n') return s; s += ch; @@ -1015,6 +1015,13 @@ string concatStringsSep(const string & sep, const Strings & ss) } +string chomp(const string & s) +{ + size_t i = s.find_last_not_of(" \n\r\t"); + return i == string::npos ? "" : string(s, 0, i); +} + + string statusToString(int status) { if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 9b8656f704..16633a0835 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -292,6 +292,10 @@ Strings tokenizeString(const string & s, const string & separators = " \t\n\r"); string concatStringsSep(const string & sep, const Strings & ss); +/* Remove trailing whitespace from a string. */ +string chomp(const string & s); + + /* Convert the exit status of a child as returned by wait() into an error string. */ string statusToString(int status); -- cgit 1.4.1