Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libfetchers/git-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ std::vector<std::tuple<GitRepoImpl::Submodule, Hash>> GitRepoImpl::getSubmodules
auto [fdTemp, pathTemp] = createTempFile("nix-git-submodules");
try {
writeFull(fdTemp.get(), configS);
} catch (SysError & e) {
} catch (SystemError & e) {
e.addTrace({}, "while writing .gitmodules file to temporary file");
throw;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libmain/plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void initPlugins()
checkInterrupt();
pluginFiles.emplace_back(ent.path());
}
} catch (SysError & e) {
if (e.errNo != ENOTDIR)
} catch (SystemError & e) {
if (!e.is(std::errc::not_a_directory))
throw;
pluginFiles.emplace_back(pluginFile);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/build/derivation-building-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,8 @@ HookReply DerivationBuildingGoal::tryBuildHook(const DerivationOptions<StorePath
else if (reply != "accept")
throw Error("bad hook reply '%s'", reply);

} catch (SysError & e) {
if (e.errNo == EPIPE) {
} catch (SystemError & e) {
if (e.is(std::errc::broken_pipe)) {
printError("build hook died unexpectedly: %s", chomp(drainFD(worker.hook->fromHook.readSide.get())));
worker.hook = 0;
return rpDecline;
Expand Down
12 changes: 6 additions & 6 deletions src/libstore/builtins/buildenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,

try {
srcFiles = DirectoryIterator{srcDir};
} catch (SysError & e) {
if (e.errNo == ENOTDIR) {
} catch (SystemError & e) {
if (e.is(std::errc::not_a_directory)) {
warn("not including '%s' in the user environment because it's not a directory", srcDir);
return;
}
Expand All @@ -54,8 +54,8 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
try {
if (stat(srcFile.c_str(), &srcSt) == -1)
throw SysError("getting status of '%1%'", srcFile);
} catch (SysError & e) {
if (e.errNo == ENOENT || e.errNo == ENOTDIR) {
} catch (SystemError & e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? Above it's throwing a SysError with an errno, but where does the errno get converted to an std::errc that can be caught here?

Copy link
Contributor

@xokdvium xokdvium Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now store a std::error_code (system_category) and it's comparable to a std::errc even on windows since fd0bcd9. In unix-like system_category is the same as generic_category, which is just the errno. On windows the comparison goes through the first overload of equivalent virtual function https://en.cppreference.com/w/cpp/error/error_category/equivalent.html, which implements a mapping from windows errors to POSIX ones (std::error_condition is implicitly constructible from std::errc: https://en.cppreference.com/w/cpp/error/error_condition/error_condition.html that uses the generic_category: https://en.cppreference.com/w/cpp/error/errc/make_error_condition.html)

if (e.is(std::errc::no_such_file_or_directory) || e.is(std::errc::not_a_directory)) {
warn("skipping dangling symlink '%s'", dstFile);
continue;
}
Expand Down Expand Up @@ -141,8 +141,8 @@ void buildProfile(const Path & out, Packages && pkgs)
readFile(pkgDir + "/nix-support/propagated-user-env-packages"), " \n"))
if (!done.count(p))
postponed.insert(p);
} catch (SysError & e) {
if (e.errNo != ENOENT && e.errNo != ENOTDIR)
} catch (SystemError & e) {
if (!e.is(std::errc::no_such_file_or_directory) && !e.is(std::errc::not_a_directory))
throw;
}
};
Expand Down
17 changes: 9 additions & 8 deletions src/libstore/gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ void LocalStore::addTempRoot(const StorePath & path)
*fdRootsSocket = createUnixDomainSocket();
try {
nix::connect(toSocket(fdRootsSocket->get()), socketPath);
} catch (SysError & e) {
} catch (SystemError & e) {
/* The garbage collector may have exited or not
created the socket yet, so we need to restart. */
if (e.errNo == ECONNREFUSED || e.errNo == ENOENT) {
if (e.is(std::errc::connection_refused) || e.is(std::errc::no_such_file_or_directory)) {
debug("GC socket connection refused: %s", e.msg());
fdRootsSocket->close();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
Expand All @@ -135,10 +135,10 @@ void LocalStore::addTempRoot(const StorePath & path)
readFull(fdRootsSocket->get(), &c, 1);
assert(c == '1');
debug("got ack for GC root '%s'", printStorePath(path));
} catch (SysError & e) {
} catch (SystemError & e) {
/* The garbage collector may have exited, so we need to
restart. */
if (e.errNo == EPIPE || e.errNo == ECONNRESET) {
if (e.is(std::errc::broken_pipe) || e.is(std::errc::connection_reset)) {
debug("GC socket disconnected");
fdRootsSocket->close();
goto restart;
Expand Down Expand Up @@ -280,9 +280,10 @@ void LocalStore::findRoots(const Path & path, std::filesystem::file_type type, R
throw;
}

catch (SysError & e) {
catch (SystemError & e) {
/* We only ignore permanent failures. */
if (e.errNo == EACCES || e.errNo == ENOENT || e.errNo == ENOTDIR)
if (e.is(std::errc::permission_denied) || e.is(std::errc::no_such_file_or_directory)
|| e.is(std::errc::not_a_directory))
printInfo("cannot read potential root '%1%'", path);
else
throw;
Expand Down Expand Up @@ -347,8 +348,8 @@ static void readFileRoots(const std::filesystem::path & path, UncheckedRoots & r
{
try {
roots[readFile(path)].emplace(path.string());
} catch (SysError & e) {
if (e.errNo != ENOENT && e.errNo != EACCES)
} catch (SystemError & e) {
if (!e.is(std::errc::no_such_file_or_directory) && !e.is(std::errc::permission_denied))
throw;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ LocalStore::LocalStore(ref<const Config> config)
Path globalLockPath = dbDir + "/big-lock";
try {
globalLock = openLockFile(globalLockPath.c_str(), true);
} catch (SysError & e) {
if (e.errNo == EACCES || e.errNo == EPERM) {
} catch (SystemError & e) {
if (e.is(std::errc::permission_denied) || e.is(std::errc::operation_not_permitted)) {
e.addTrace(
{},
"This command may have been run as non-root in a single-user Nix installation,\n"
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/remote-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ ref<const ValidPathInfo> RemoteStore::addCAToStore(
}
}
conn.processStderr();
} catch (SysError & e) {
} catch (SystemError & e) {
/* Daemon closed while we were sending the path. Probably OOM
or I/O error. */
if (e.errNo == EPIPE)
if (e.is(std::errc::broken_pipe))
try {
conn.processStderr();
} catch (EndOfFile & e) {
Expand Down
4 changes: 2 additions & 2 deletions src/libutil/file-system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ bool pathAccessible(const std::filesystem::path & path)
{
try {
return pathExists(path.string());
} catch (SysError & e) {
} catch (SystemError & e) {
// swallow EPERM
if (e.errNo == EPERM)
if (e.is(std::errc::operation_not_permitted))
return false;
throw;
}
Expand Down
4 changes: 2 additions & 2 deletions src/nix/build-remote/build-remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ static int main_build_remote(int argc, char ** argv)
};
try {
setUpdateLock(storeUri);
} catch (SysError & e) {
if (e.errNo != ENAMETOOLONG)
} catch (SystemError & e) {
if (!e.is(std::errc::filename_too_long))
throw;
// Try again hashing the store URL so we have a shorter path
auto h = hashString(HashAlgorithm::MD5, storeUri);
Expand Down
Loading