mirror of
https://github.com/NixOS/nix
synced 2025-06-30 03:23:16 +02:00
remove 'format' from Error constructor calls
This commit is contained in:
parent
d3052197fe
commit
e4fb9a3849
52 changed files with 424 additions and 407 deletions
|
@ -46,7 +46,7 @@ static void dumpContents(const Path & path, size_t size,
|
|||
sink << "contents" << size;
|
||||
|
||||
AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
|
||||
if (!fd) throw SysError(format("opening file '%1%'") % path);
|
||||
if (!fd) throw SysError("opening file '%1%'", path);
|
||||
|
||||
std::vector<unsigned char> buf(65536);
|
||||
size_t left = size;
|
||||
|
@ -68,7 +68,7 @@ static void dump(const Path & path, Sink & sink, PathFilter & filter)
|
|||
|
||||
struct stat st;
|
||||
if (lstat(path.c_str(), &st))
|
||||
throw SysError(format("getting attributes of path '%1%'") % path);
|
||||
throw SysError("getting attributes of path '%1%'", path);
|
||||
|
||||
sink << "(";
|
||||
|
||||
|
@ -94,8 +94,9 @@ static void dump(const Path & path, Sink & sink, PathFilter & filter)
|
|||
name.erase(pos);
|
||||
}
|
||||
if (unhacked.find(name) != unhacked.end())
|
||||
throw Error(format("file name collision in between '%1%' and '%2%'")
|
||||
% (path + "/" + unhacked[name]) % (path + "/" + i.name));
|
||||
throw Error("file name collision in between '%1%' and '%2%'",
|
||||
(path + "/" + unhacked[name]),
|
||||
(path + "/" + i.name));
|
||||
unhacked[name] = i.name;
|
||||
} else
|
||||
unhacked[i.name] = i.name;
|
||||
|
@ -111,7 +112,7 @@ static void dump(const Path & path, Sink & sink, PathFilter & filter)
|
|||
else if (S_ISLNK(st.st_mode))
|
||||
sink << "type" << "symlink" << "target" << readLink(path);
|
||||
|
||||
else throw Error(format("file '%1%' has an unsupported type") % path);
|
||||
else throw Error("file '%1%' has an unsupported type", path);
|
||||
|
||||
sink << ")";
|
||||
}
|
||||
|
@ -247,7 +248,7 @@ static void parse(ParseSink & sink, Source & source, const Path & path)
|
|||
} else if (s == "name") {
|
||||
name = readString(source);
|
||||
if (name.empty() || name == "." || name == ".." || name.find('/') != string::npos || name.find((char) 0) != string::npos)
|
||||
throw Error(format("NAR contains invalid file name '%1%'") % name);
|
||||
throw Error("NAR contains invalid file name '%1%'", name);
|
||||
if (name <= prevName)
|
||||
throw Error("NAR directory is not sorted");
|
||||
prevName = name;
|
||||
|
@ -303,14 +304,14 @@ struct RestoreSink : ParseSink
|
|||
{
|
||||
Path p = dstPath + path;
|
||||
if (mkdir(p.c_str(), 0777) == -1)
|
||||
throw SysError(format("creating directory '%1%'") % p);
|
||||
throw SysError("creating directory '%1%'", p);
|
||||
};
|
||||
|
||||
void createRegularFile(const Path & path)
|
||||
{
|
||||
Path p = dstPath + path;
|
||||
fd = open(p.c_str(), O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC, 0666);
|
||||
if (!fd) throw SysError(format("creating file '%1%'") % p);
|
||||
if (!fd) throw SysError("creating file '%1%'", p);
|
||||
}
|
||||
|
||||
void isExecutable()
|
||||
|
@ -332,7 +333,7 @@ struct RestoreSink : ParseSink
|
|||
OpenSolaris). Since preallocation is just an
|
||||
optimisation, ignore it. */
|
||||
if (errno && errno != EINVAL && errno != EOPNOTSUPP && errno != ENOSYS)
|
||||
throw SysError(format("preallocating file of %1% bytes") % len);
|
||||
throw SysError("preallocating file of %1% bytes", len);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ void Args::parseCmdline(const Strings & _cmdline)
|
|||
}
|
||||
else if (!dashDash && std::string(arg, 0, 1) == "-") {
|
||||
if (!processFlag(pos, cmdline.end()))
|
||||
throw UsageError(format("unrecognised flag '%1%'") % arg);
|
||||
throw UsageError("unrecognised flag '%1%'", arg);
|
||||
}
|
||||
else {
|
||||
pendingArgs.push_back(*pos++);
|
||||
|
@ -104,8 +104,9 @@ bool Args::processFlag(Strings::iterator & pos, Strings::iterator end)
|
|||
for (size_t n = 0 ; n < flag.arity; ++n) {
|
||||
if (pos == end) {
|
||||
if (flag.arity == ArityAny) break;
|
||||
throw UsageError(format("flag '%1%' requires %2% argument(s)")
|
||||
% name % flag.arity);
|
||||
throw UsageError("flag '%1%' requires %2% argument(s)",
|
||||
name,
|
||||
flag.arity);
|
||||
}
|
||||
args.push_back(*pos++);
|
||||
}
|
||||
|
@ -133,7 +134,7 @@ bool Args::processArgs(const Strings & args, bool finish)
|
|||
{
|
||||
if (expectedArgs.empty()) {
|
||||
if (!args.empty())
|
||||
throw UsageError(format("unexpected argument '%1%'") % args.front());
|
||||
throw UsageError("unexpected argument '%1%'", args.front());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -481,7 +481,7 @@ ref<CompressionSink> makeCompressionSink(const std::string & method, Sink & next
|
|||
else if (method == "br")
|
||||
return make_ref<BrotliCompressionSink>(nextSink);
|
||||
else
|
||||
throw UnknownCompressionMethod(format("unknown compression method '%s'") % method);
|
||||
throw UnknownCompressionMethod("unknown compression method '%s'", method);
|
||||
}
|
||||
|
||||
ref<std::string> compress(const std::string & method, const std::string & in, const bool parallel)
|
||||
|
|
|
@ -92,15 +92,15 @@ public:
|
|||
{
|
||||
fmt.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit);
|
||||
}
|
||||
hintformat(const hintformat &hf)
|
||||
: fmt(hf.fmt)
|
||||
{}
|
||||
template<class T>
|
||||
hintformat& operator%(const T &value)
|
||||
{
|
||||
fmt % yellowify(value);
|
||||
return *this;
|
||||
}
|
||||
hintformat(const hintformat &hf)
|
||||
: fmt(hf.fmt)
|
||||
{}
|
||||
|
||||
|
||||
std::string str() const
|
||||
|
|
|
@ -93,7 +93,9 @@ public:
|
|||
|
||||
template<typename... Args>
|
||||
BaseError(unsigned int status, const Args & ... args)
|
||||
: err(hintfmt(args...))
|
||||
: err { .level = lvlError,
|
||||
.hint = hintfmt(args...)
|
||||
}
|
||||
, status(status)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ Path canonPath(const Path & path, bool resolveSymlinks)
|
|||
string s;
|
||||
|
||||
if (path[0] != '/')
|
||||
throw Error(format("not an absolute path: '%1%'") % path);
|
||||
throw Error("not an absolute path: '%1%'", path);
|
||||
|
||||
string::const_iterator i = path.begin(), end = path.end();
|
||||
string temp;
|
||||
|
@ -165,7 +165,7 @@ Path canonPath(const Path & path, bool resolveSymlinks)
|
|||
the symlink target might contain new symlinks). */
|
||||
if (resolveSymlinks && isLink(s)) {
|
||||
if (++followCount >= maxFollow)
|
||||
throw Error(format("infinite symlink recursion in path '%1%'") % path);
|
||||
throw Error("infinite symlink recursion in path '%1%'", path);
|
||||
temp = absPath(readLink(s), dirOf(s))
|
||||
+ string(i, end);
|
||||
i = temp.begin(); /* restart */
|
||||
|
@ -226,7 +226,7 @@ struct stat lstat(const Path & path)
|
|||
{
|
||||
struct stat st;
|
||||
if (lstat(path.c_str(), &st))
|
||||
throw SysError(format("getting status of '%1%'") % path);
|
||||
throw SysError("getting status of '%1%'", path);
|
||||
return st;
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,7 @@ bool pathExists(const Path & path)
|
|||
res = lstat(path.c_str(), &st);
|
||||
if (!res) return true;
|
||||
if (errno != ENOENT && errno != ENOTDIR)
|
||||
throw SysError(format("getting status of %1%") % path);
|
||||
throw SysError("getting status of %1%", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ DirEntries readDirectory(const Path & path)
|
|||
entries.reserve(64);
|
||||
|
||||
AutoCloseDir dir(opendir(path.c_str()));
|
||||
if (!dir) throw SysError(format("opening directory '%1%'") % path);
|
||||
if (!dir) throw SysError("opening directory '%1%'", path);
|
||||
|
||||
struct dirent * dirent;
|
||||
while (errno = 0, dirent = readdir(dir.get())) { /* sic */
|
||||
|
@ -289,7 +289,7 @@ DirEntries readDirectory(const Path & path)
|
|||
#endif
|
||||
);
|
||||
}
|
||||
if (errno) throw SysError(format("reading directory '%1%'") % path);
|
||||
if (errno) throw SysError("reading directory '%1%'", path);
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ string readFile(const Path & path, bool drain)
|
|||
{
|
||||
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 drain ? drainFD(fd.get()) : readFile(fd.get());
|
||||
}
|
||||
|
||||
|
@ -339,7 +339,7 @@ void writeFile(const Path & path, const string & s, mode_t mode)
|
|||
{
|
||||
AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, mode);
|
||||
if (!fd)
|
||||
throw SysError(format("opening file '%1%'") % path);
|
||||
throw SysError("opening file '%1%'", path);
|
||||
writeFull(fd.get(), s);
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ void writeFile(const Path & path, Source & source, mode_t mode)
|
|||
{
|
||||
AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, mode);
|
||||
if (!fd)
|
||||
throw SysError(format("opening file '%1%'") % path);
|
||||
throw SysError("opening file '%1%'", path);
|
||||
|
||||
std::vector<unsigned char> buf(64 * 1024);
|
||||
|
||||
|
@ -396,7 +396,7 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed)
|
|||
struct stat st;
|
||||
if (lstat(path.c_str(), &st) == -1) {
|
||||
if (errno == ENOENT) return;
|
||||
throw SysError(format("getting status of '%1%'") % path);
|
||||
throw SysError("getting status of '%1%'", path);
|
||||
}
|
||||
|
||||
if (!S_ISDIR(st.st_mode) && st.st_nlink == 1)
|
||||
|
@ -407,7 +407,7 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed)
|
|||
const auto PERM_MASK = S_IRUSR | S_IWUSR | S_IXUSR;
|
||||
if ((st.st_mode & PERM_MASK) != PERM_MASK) {
|
||||
if (chmod(path.c_str(), st.st_mode | PERM_MASK) == -1)
|
||||
throw SysError(format("chmod '%1%'") % path);
|
||||
throw SysError("chmod '%1%'", path);
|
||||
}
|
||||
|
||||
for (auto & i : readDirectory(path))
|
||||
|
@ -416,7 +416,7 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed)
|
|||
|
||||
if (remove(path.c_str()) == -1) {
|
||||
if (errno == ENOENT) return;
|
||||
throw SysError(format("cannot unlink '%1%'") % path);
|
||||
throw SysError("cannot unlink '%1%'", path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -468,12 +468,12 @@ Path createTempDir(const Path & tmpRoot, const Path & prefix,
|
|||
"wheel", then "tar" will fail to unpack archives that
|
||||
have the setgid bit set on directories. */
|
||||
if (chown(tmpDir.c_str(), (uid_t) -1, getegid()) != 0)
|
||||
throw SysError(format("setting group of directory '%1%'") % tmpDir);
|
||||
throw SysError("setting group of directory '%1%'", tmpDir);
|
||||
#endif
|
||||
return tmpDir;
|
||||
}
|
||||
if (errno != EEXIST)
|
||||
throw SysError(format("creating directory '%1%'") % tmpDir);
|
||||
throw SysError("creating directory '%1%'", tmpDir);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -555,15 +555,15 @@ Paths createDirs(const Path & path)
|
|||
if (lstat(path.c_str(), &st) == -1) {
|
||||
created = createDirs(dirOf(path));
|
||||
if (mkdir(path.c_str(), 0777) == -1 && errno != EEXIST)
|
||||
throw SysError(format("creating directory '%1%'") % path);
|
||||
throw SysError("creating directory '%1%'", path);
|
||||
st = lstat(path);
|
||||
created.push_back(path);
|
||||
}
|
||||
|
||||
if (S_ISLNK(st.st_mode) && stat(path.c_str(), &st) == -1)
|
||||
throw SysError(format("statting symlink '%1%'") % path);
|
||||
throw SysError("statting symlink '%1%'", path);
|
||||
|
||||
if (!S_ISDIR(st.st_mode)) throw Error(format("'%1%' is not a directory") % path);
|
||||
if (!S_ISDIR(st.st_mode)) throw Error("'%1%' is not a directory", path);
|
||||
|
||||
return created;
|
||||
}
|
||||
|
@ -572,7 +572,7 @@ Paths createDirs(const Path & path)
|
|||
void createSymlink(const Path & target, const Path & link)
|
||||
{
|
||||
if (symlink(target.c_str(), link.c_str()))
|
||||
throw SysError(format("creating symlink from '%1%' to '%2%'") % link % target);
|
||||
throw SysError("creating symlink from '%1%' to '%2%'", link, target);
|
||||
}
|
||||
|
||||
|
||||
|
@ -589,7 +589,7 @@ void replaceSymlink(const Path & target, const Path & link)
|
|||
}
|
||||
|
||||
if (rename(tmp.c_str(), link.c_str()) != 0)
|
||||
throw SysError(format("renaming '%1%' to '%2%'") % tmp % link);
|
||||
throw SysError("renaming '%1%' to '%2%'", tmp, link);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -694,7 +694,7 @@ AutoDelete::~AutoDelete()
|
|||
deletePath(path);
|
||||
else {
|
||||
if (remove(path.c_str()) == -1)
|
||||
throw SysError(format("cannot unlink '%1%'") % path);
|
||||
throw SysError("cannot unlink '%1%'", path);
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
|
@ -760,7 +760,7 @@ void AutoCloseFD::close()
|
|||
if (fd != -1) {
|
||||
if (::close(fd) == -1)
|
||||
/* This should never happen. */
|
||||
throw SysError(format("closing file descriptor %1%") % fd);
|
||||
throw SysError("closing file descriptor %1%", fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -920,7 +920,7 @@ void killUser(uid_t uid)
|
|||
#endif
|
||||
if (errno == ESRCH) break; /* no more processes */
|
||||
if (errno != EINTR)
|
||||
throw SysError(format("cannot kill processes for uid '%1%'") % uid);
|
||||
throw SysError("cannot kill processes for uid '%1%'", uid);
|
||||
}
|
||||
|
||||
_exit(0);
|
||||
|
@ -928,7 +928,7 @@ void killUser(uid_t uid)
|
|||
|
||||
int status = pid.wait();
|
||||
if (status != 0)
|
||||
throw Error(format("cannot kill processes for uid '%1%': %2%") % uid % statusToString(status));
|
||||
throw Error("cannot kill processes for uid '%1%': %2%", uid, statusToString(status));
|
||||
|
||||
/* !!! We should really do some check to make sure that there are
|
||||
no processes left running under `uid', but there is no portable
|
||||
|
@ -1322,7 +1322,7 @@ void ignoreException()
|
|||
try {
|
||||
throw;
|
||||
} catch (std::exception & e) {
|
||||
printError(format("error (ignored): %1%") % e.what());
|
||||
printError("error (ignored): %1%", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1440,7 +1440,7 @@ void callFailure(const std::function<void(std::exception_ptr exc)> & failure, st
|
|||
try {
|
||||
failure(exc);
|
||||
} catch (std::exception & e) {
|
||||
printError(format("uncaught exception: %s") % e.what());
|
||||
printError("uncaught exception: %s", e.what());
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue