treewide: derive all lix exceptions from BaseError
even the non-errors. we should probably insert a BaseException here. Change-Id: I1b1af8ba0bf49251fe9d1a24c6559db3ef4a59d2
This commit is contained in:
+2
-1
@@ -2,6 +2,7 @@
|
||||
#include "lix/libstore/local-store.hh"
|
||||
#include "lix/libstore/pathlocks.hh"
|
||||
#include "lix/libutil/async.hh"
|
||||
#include "lix/libutil/error.hh"
|
||||
#include "lix/libutil/processes.hh"
|
||||
#include "lix/libutil/result.hh"
|
||||
#include "lix/libutil/signals.hh"
|
||||
@@ -399,7 +400,7 @@ try {
|
||||
}
|
||||
|
||||
|
||||
struct GCLimitReached : std::exception { };
|
||||
struct GCLimitReached : BaseException { };
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* @file Checked arithmetic with classes that make it hard to accidentally make something an unchecked operation.
|
||||
*/
|
||||
|
||||
#include "lix/libutil/error.hh"
|
||||
#include <compare>
|
||||
#include <concepts> // IWYU pragma: keep
|
||||
#include <exception>
|
||||
@@ -13,7 +14,7 @@
|
||||
|
||||
namespace nix::checked {
|
||||
|
||||
class DivideByZero : std::exception
|
||||
struct DivideByZero : BaseException
|
||||
{};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "lix/libutil/exit.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
Exit::~Exit() {}
|
||||
|
||||
}
|
||||
+2
-3
@@ -1,20 +1,19 @@
|
||||
#pragma once
|
||||
///@file
|
||||
|
||||
#include <exception>
|
||||
#include "lix/libutil/error.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
/**
|
||||
* Exit the program with a given exit code.
|
||||
*/
|
||||
class Exit : public std::exception
|
||||
class Exit : public BaseException
|
||||
{
|
||||
public:
|
||||
int status;
|
||||
Exit() : status(0) { }
|
||||
explicit Exit(int status) : status(status) { }
|
||||
virtual ~Exit();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ libutil_sources = files(
|
||||
'error.cc',
|
||||
'escape-char.cc',
|
||||
'escape-string.cc',
|
||||
'exit.cc',
|
||||
'experimental-features.cc',
|
||||
'file-descriptor.cc',
|
||||
'file-system.cc',
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "lix/libstore/store-api.hh"
|
||||
#include "lix/libstore/fs-accessor.hh"
|
||||
#include "lix/libmain/shared.hh"
|
||||
#include "lix/libutil/error.hh"
|
||||
#include "why-depends.hh"
|
||||
|
||||
#include <queue>
|
||||
@@ -173,7 +174,7 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
|
||||
and `dependency`. */
|
||||
std::function<void(Node &, const std::string &, const std::string &)> printNode;
|
||||
|
||||
struct BailOut : std::exception { };
|
||||
struct BailOut : BaseException { };
|
||||
|
||||
printNode = [&](Node & node, const std::string & firstPad, const std::string & tailPad) {
|
||||
auto pathS = store->printStorePath(node.path);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "lix/libstore/filetransfer.hh"
|
||||
#include "lix/libutil/compression.hh"
|
||||
#include "lix/libutil/error.hh"
|
||||
#include "lix/libutil/signals.hh"
|
||||
#include "lix/libutil/thread-name.hh"
|
||||
|
||||
@@ -203,7 +204,7 @@ serveHTTP(std::string status, std::string headers, std::function<std::string()>
|
||||
|
||||
TEST(FileTransfer, exceptionAbortsDownload)
|
||||
{
|
||||
struct Done : std::exception
|
||||
struct Done : BaseException
|
||||
{};
|
||||
|
||||
auto ft = makeFileTransfer();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
///@file
|
||||
|
||||
#include "lix/libutil/error.hh"
|
||||
#include <compare>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -127,7 +128,7 @@ struct ParseResult {
|
||||
/**
|
||||
* A parse error.
|
||||
*/
|
||||
struct ParseError : std::exception {
|
||||
struct ParseError : BaseException {
|
||||
std::string expected;
|
||||
std::string rest;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "lix/libutil/closure.hh"
|
||||
#include "lix/libutil/error.hh"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace nix {
|
||||
@@ -28,7 +29,7 @@ TEST(closure, correctClosure) {
|
||||
}
|
||||
|
||||
TEST(closure, properlyHandlesDirectExceptions) {
|
||||
struct TestExn : std::exception {};
|
||||
struct TestExn : BaseException {};
|
||||
EXPECT_THROW(
|
||||
computeClosure<string>(
|
||||
{"A"},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "lix/libutil/generator.hh"
|
||||
#include "lix/libutil/error.hh"
|
||||
|
||||
#include <concepts>
|
||||
#include <cstdint>
|
||||
@@ -6,6 +7,11 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
namespace {
|
||||
MakeError(TestError, BaseError);
|
||||
MakeError(TestError2, BaseError);
|
||||
}
|
||||
|
||||
TEST(Generator, yields)
|
||||
{
|
||||
auto g = []() -> Generator<int> {
|
||||
@@ -85,8 +91,7 @@ TEST(Generator, nestsExceptions)
|
||||
co_yield 1;
|
||||
co_yield []() -> Generator<int> {
|
||||
co_yield 9;
|
||||
// NOLINTNEXTLINE(hicpp-exception-baseclass)
|
||||
throw 1;
|
||||
throw TestError("");
|
||||
co_yield 10;
|
||||
}();
|
||||
co_yield 2;
|
||||
@@ -94,7 +99,7 @@ TEST(Generator, nestsExceptions)
|
||||
|
||||
ASSERT_EQ(g.next(), 1);
|
||||
ASSERT_EQ(g.next(), 9);
|
||||
ASSERT_THROW(g.next(), int);
|
||||
ASSERT_THROW(g.next(), TestError);
|
||||
}
|
||||
|
||||
TEST(Generator, exception)
|
||||
@@ -102,22 +107,20 @@ TEST(Generator, exception)
|
||||
{
|
||||
auto g = []() -> Generator<int> {
|
||||
co_yield 1;
|
||||
// NOLINTNEXTLINE(hicpp-exception-baseclass)
|
||||
throw 1;
|
||||
throw TestError("");
|
||||
}();
|
||||
|
||||
ASSERT_EQ(g.next(), 1);
|
||||
ASSERT_THROW(g.next(), int);
|
||||
ASSERT_THROW(g.next(), TestError);
|
||||
ASSERT_FALSE(g.next().has_value());
|
||||
}
|
||||
{
|
||||
auto g = []() -> Generator<int> {
|
||||
// NOLINTNEXTLINE(hicpp-exception-baseclass)
|
||||
throw 1;
|
||||
throw TestError("");
|
||||
co_return;
|
||||
}();
|
||||
|
||||
ASSERT_THROW(g.next(), int);
|
||||
ASSERT_THROW(g.next(), TestError);
|
||||
ASSERT_FALSE(g.next().has_value());
|
||||
}
|
||||
}
|
||||
@@ -176,14 +179,12 @@ struct ThrowTransform
|
||||
|
||||
int operator()(bool)
|
||||
{
|
||||
// NOLINTNEXTLINE(hicpp-exception-baseclass)
|
||||
throw 2;
|
||||
throw TestError("");
|
||||
}
|
||||
|
||||
Generator<int, void> operator()(Generator<int> && inner)
|
||||
{
|
||||
// NOLINTNEXTLINE(hicpp-exception-baseclass)
|
||||
throw false;
|
||||
throw TestError2("");
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -198,7 +199,7 @@ TEST(Generator, transformThrows)
|
||||
}();
|
||||
|
||||
ASSERT_EQ(g.next(), 1);
|
||||
ASSERT_THROW(g.next(), int);
|
||||
ASSERT_THROW(g.next(), TestError);
|
||||
ASSERT_FALSE(g.next().has_value());
|
||||
}
|
||||
{
|
||||
@@ -211,7 +212,7 @@ TEST(Generator, transformThrows)
|
||||
}();
|
||||
|
||||
ASSERT_EQ(g.next(), 1);
|
||||
ASSERT_THROW(g.next(), bool);
|
||||
ASSERT_THROW(g.next(), TestError2);
|
||||
ASSERT_FALSE(g.next().has_value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "lix/libutil/thread-pool.hh"
|
||||
#include "lix/libutil/async.hh"
|
||||
#include "lix/libutil/error.hh"
|
||||
#include <atomic>
|
||||
#include <exception>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -51,7 +52,7 @@ TEST(ThreadPool, early_quit)
|
||||
ThreadPool t{"test", 2};
|
||||
bool ran_anyway = false;
|
||||
|
||||
struct Dead : std::exception {};
|
||||
struct Dead : BaseException {};
|
||||
|
||||
std::atomic_bool unblockA{false}, unblockB{false};
|
||||
std::atomic_bool started{false};
|
||||
@@ -92,7 +93,7 @@ TEST(ThreadPool, early_quit_async)
|
||||
ThreadPool t{"test", 2};
|
||||
bool ran_anyway = false;
|
||||
|
||||
struct Dead : std::exception {};
|
||||
struct Dead : BaseException {};
|
||||
|
||||
std::atomic_bool unblockA{false}, unblockB{false};
|
||||
std::atomic_bool started{false};
|
||||
@@ -133,7 +134,7 @@ TEST(ThreadPool, always_rethrows)
|
||||
{
|
||||
ThreadPool t{"test"};
|
||||
|
||||
struct Dead : std::exception {};
|
||||
struct Dead : BaseException {};
|
||||
|
||||
std::atomic_bool flag{false};
|
||||
|
||||
@@ -155,7 +156,7 @@ TEST(ThreadPool, always_rethrows_async)
|
||||
{
|
||||
ThreadPool t{"test"};
|
||||
|
||||
struct Dead : std::exception {};
|
||||
struct Dead : BaseException {};
|
||||
|
||||
std::atomic_bool flag{false};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user