diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 137fe7198e8d61c4461f3ef5a8838393f40e1a3d..a185d5785730bd5d7691a00c8a1184d77c739ea6 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -2,6 +2,7 @@ #include "value.hh" #include "symbol-table.hh" +#include "error.hh" #include <map> diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 10e8c6b4255b69155831f8251e15b5ec71cb38ba..657ce3001482ceb657549b7e6e89ffbf123244e5 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1124,7 +1124,7 @@ static void prim_toFile(EvalState & state, const Pos & pos, Value * * args, Valu ErrorInfo { .hint = hintfmt( "in 'toFile': the file named '%1%' must not contain a reference " - "to a derivation but contains (%2%)" + "to a derivation but contains (%2%)", name, path), .nixCode = NixCode { .errPos = pos } diff --git a/src/libmain/stack.cc b/src/libmain/stack.cc index e6224de7d28f10e820fb3082fff03d154a3a5aca..b0a4a4c5dbe40e38f375b43630170724f834ff54 100644 --- a/src/libmain/stack.cc +++ b/src/libmain/stack.cc @@ -1,4 +1,4 @@ -#include "types.hh" +#include "error.hh" #include <cstring> #include <cstddef> diff --git a/src/libstore/build.cc b/src/libstore/build.cc index d6f3553d96da1e95d9e3464fda0d5edfb2046c35..0359b10ac5d9d6e6271ec53bce8f7cac7170b78a 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -547,7 +547,7 @@ UserLock::UserLock() /* Copy the result of getgrnam. */ Strings users; for (char * * p = gr->gr_mem; *p; ++p) { - debug(format("found build user '%1%'") % *p); + debug("found build user '%1%'", *p); users.push_back(*p); } @@ -558,7 +558,7 @@ UserLock::UserLock() /* Find a user account that isn't currently in use for another build. */ for (auto & i : users) { - debug(format("trying user '%1%'") % i); + debug("trying user '%1%'", i); struct passwd * pw = getpwnam(i.c_str()); if (!pw) @@ -1794,7 +1794,7 @@ HookReply DerivationGoal::tryBuildHook() } } - debug(format("hook reply is '%1%'") % reply); + debug("hook reply is '%1%'", reply); if (reply == "decline") return rpDecline; @@ -2255,7 +2255,7 @@ void DerivationGoal::startBuilder() startDaemon(); /* Run the builder. */ - printMsg(lvlChatty, format("executing builder '%1%'") % drv->builder); + printMsg(lvlChatty, "executing builder '%1%'", drv->builder); /* Create the log file. */ Path logFile = openLogFile(); @@ -3195,7 +3195,7 @@ void DerivationGoal::runChild() filesystem that we want in the chroot environment. */ auto doBind = [&](const Path & source, const Path & target, bool optional = false) { - debug(format("bind mounting '%1%' to '%2%'") % source % target); + debug("bind mounting '%1%' to '%2%'", source, target); struct stat st; if (stat(source.c_str(), &st) == -1) { if (optional && errno == ENOENT) @@ -3572,7 +3572,7 @@ static void moveCheckToStore(const Path & src, const Path & dst) directory's parent link ".."). */ struct stat st; if (lstat(src.c_str(), &st) == -1) { - throw SysError(format("getting attributes of path '%1%'") % src); + throw SysError("getting attributes of path '%1%'", src); } bool changePerm = (geteuid() && S_ISDIR(st.st_mode) && !(st.st_mode & S_IWUSR)); @@ -3581,7 +3581,7 @@ static void moveCheckToStore(const Path & src, const Path & dst) chmod_(src, st.st_mode | S_IWUSR); if (rename(src.c_str(), dst.c_str())) - throw SysError(format("renaming '%1%' to '%2%'") % src % dst); + throw SysError("renaming '%1%' to '%2%'", src, dst); if (changePerm) chmod_(dst, st.st_mode); @@ -4911,15 +4911,15 @@ void Worker::waitForInput() // FIXME: is there a cleaner way to handle pt close // than EIO? Is this even standard? if (rd == 0 || (rd == -1 && errno == EIO)) { - debug(format("%1%: got EOF") % goal->getName()); + debug("%1%: got EOF", goal->getName()); goal->handleEOF(k); j->fds.erase(k); } else if (rd == -1) { if (errno != EINTR) throw SysError("%s: read failed", goal->getName()); } else { - printMsg(lvlVomit, format("%1%: read %2% bytes") - % goal->getName() % rd); + printMsg(lvlVomit, "%1%: read %2% bytes", + goal->getName(), rd); string data((char *) buffer.data(), rd); j->lastOutput = after; goal->handleChildOutput(k, data); diff --git a/src/libstore/filetransfer.hh b/src/libstore/filetransfer.hh index 517b1a7d3d9ffa510978d5a124e4b726ba21aa2a..11dca2fe0f0a4ddc6780acf8819cacf08765c5a5 100644 --- a/src/libstore/filetransfer.hh +++ b/src/libstore/filetransfer.hh @@ -103,8 +103,9 @@ class FileTransferError : public Error { public: FileTransfer::Error error; + template<typename... Args> FileTransferError(FileTransfer::Error error, const Args & ... args) - : Error(fs), error(error) + : Error(args...), error(error) { } }; diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 1f16a22b117bfebc244ca1f0cf3f257139e61af9..eb7548543090ac0c6aea1f603b274793e0300a55 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -6,6 +6,7 @@ #include "derivations.hh" #include "nar-info.hh" #include "references.hh" +#include "error.hh" #include <iostream> #include <algorithm> diff --git a/src/libstore/sqlite.hh b/src/libstore/sqlite.hh index ce27033c927bb09479fd76e195bcc1df642b059b..ccfac48d8eb5603dfe9e90b6dc794c75b57f19e7 100644 --- a/src/libstore/sqlite.hh +++ b/src/libstore/sqlite.hh @@ -3,7 +3,7 @@ #include <functional> #include <string> -#include "types.hh" +#include "error.hh" struct sqlite3; struct sqlite3_stmt; diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 423b99c96dfd9392750c8720a8fb4f1e6a09066d..10d6e89bb7ca9608380040d8371ca2fa1b06a781 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -101,15 +101,8 @@ bool Args::processFlag(Strings::iterator & pos, Strings::iterator end) std::vector<std::string> args; for (size_t n = 0 ; n < flag.handler.arity; ++n) { if (pos == end) { -<<<<<<< HEAD - if (flag.arity == ArityAny) break; - throw UsageError("flag '%1%' requires %2% argument(s)", - name, - flag.arity); -======= if (flag.handler.arity == ArityAny) break; throw UsageError("flag '%s' requires %d argument(s)", name, flag.handler.arity); ->>>>>>> master } args.push_back(*pos++); } diff --git a/src/libutil/error.hh b/src/libutil/error.hh index 7e2cca2f97ec4699ed25f46af73a8a1613cd1b4e..19c6e35a1c0273ffe1925fea676ab46f821a0378 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -2,6 +2,7 @@ #include "ref.hh" +#include "types.hh" #include <list> #include <memory> @@ -21,9 +22,6 @@ namespace nix { -using std::list; -using std::vector; - typedef enum { lvlError = 0, lvlWarn, diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index bb7d356c8e91ef2c1fb0cc4f34ff34000430980f..39692a29113e9eb10c60467d3e16a834a101b635 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -1,6 +1,7 @@ #pragma once #include "types.hh" +#include "error.hh" namespace nix { diff --git a/src/libutil/types.hh b/src/libutil/types.hh index a831b99245bc1b904ab7ab6643eef8b3c0873647..4d783b5643463ac500946ceb44693566e9a7e127 100644 --- a/src/libutil/types.hh +++ b/src/libutil/types.hh @@ -13,6 +13,7 @@ namespace nix { using std::list; using std::set; using std::vector; +using std::string; typedef list<std::string> Strings; typedef set<std::string> StringSet; diff --git a/src/libutil/url.hh b/src/libutil/url.hh index 1503023a2fc6a63c8988dc9b27320c3267022135..a184eadce07ce7ea3d1b243a95358f29c057d4c8 100644 --- a/src/libutil/url.hh +++ b/src/libutil/url.hh @@ -1,6 +1,6 @@ #pragma once -#include "types.hh" +#include "error.hh" #include <regex> diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 8207ff7011718fac11b8bfd309971ba11179cb99..ac7c2967b4a937b47f7d4772168af9c9706e22eb 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -276,7 +276,7 @@ DirEntries readDirectory(DIR *dir, const Path & path) DirEntries readDirectory(const Path & path) { AutoCloseDir dir(opendir(path.c_str())); - if (!dir) throw SysError(format("opening directory '%1%'") % path); + if (!dir) throw SysError("opening directory '%1%'", path); return readDirectory(dir.get(), path); } @@ -306,7 +306,7 @@ string readFile(const Path & path) { AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC); if (!fd) - throw SysError(format("opening file '%1%'") % path); + throw SysError("opening file '%1%'", path); return readFile(fd.get()); } @@ -394,15 +394,15 @@ static void _deletePath(int parentfd, const Path & path, unsigned long long & by const auto PERM_MASK = S_IRUSR | S_IWUSR | S_IXUSR; if ((st.st_mode & PERM_MASK) != PERM_MASK) { if (fchmodat(parentfd, name.c_str(), st.st_mode | PERM_MASK, 0) == -1) - throw SysError(format("chmod '%1%'") % path); + throw SysError("chmod '%1%'", path); } int fd = openat(parentfd, path.c_str(), O_RDONLY); if (!fd) - throw SysError(format("opening directory '%1%'") % path); + throw SysError("opening directory '%1%'", path); AutoCloseDir dir(fdopendir(fd)); if (!dir) - throw SysError(format("opening directory '%1%'") % path); + throw SysError("opening directory '%1%'", path); for (auto & i : readDirectory(dir.get(), path)) _deletePath(dirfd(dir.get()), path + "/" + i.name, bytesFreed); } @@ -426,7 +426,7 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed) // for backwards compatibility. if (errno == ENOENT) return; - throw SysError(format("opening directory '%1%'") % path); + throw SysError("opening directory '%1%'", path); } _deletePath(dirfd.get(), path, bytesFreed); @@ -845,7 +845,7 @@ int Pid::kill() { assert(pid != -1); - debug(format("killing process %1%") % pid); + debug("killing process %1%", pid); /* Send the requested signal to the child. If it has its own process group, send the signal to every process in the child @@ -903,7 +903,7 @@ pid_t Pid::release() void killUser(uid_t uid) { - debug(format("killing all processes running under uid '%1%'") % uid); + debug("killing all processes running under uid '%1%'", uid); assert(uid != 0); /* just to be safe... */