1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-05 16:31:47 +02:00

Merge pull request #11167 from NixOS/repl-test-rejiggle

Fix repl test for `buildReadlineNoMarkdown`
This commit is contained in:
Robert Hensing 2024-07-27 00:55:57 +02:00 committed by GitHub
commit 861bd102a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 302 additions and 157 deletions

View file

@ -6,6 +6,8 @@
#include <vector>
#include <limits>
#include "error.hh"
namespace nix {
/**
@ -30,7 +32,7 @@ private:
auto & addChunk()
{
if (size_ >= std::numeric_limits<uint32_t>::max() - ChunkSize)
abort();
unreachable();
chunks.emplace_back();
chunks.back().reserve(ChunkSize);
return chunks.back();

View file

@ -1,3 +1,5 @@
#include <algorithm>
#include "error.hh"
#include "environment-variables.hh"
#include "signals.hh"
@ -430,4 +432,36 @@ std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool s
return out;
}
/** Write to stderr in a robust and minimal way, considering that the process
* may be in a bad state.
*/
static void writeErr(std::string_view buf)
{
while (!buf.empty()) {
auto n = write(STDERR_FILENO, buf.data(), buf.size());
if (n < 0) {
if (errno == EINTR) continue;
abort();
}
buf = buf.substr(n);
}
}
void panic(std::string_view msg)
{
writeErr("\n\n" ANSI_RED "terminating due to unexpected unrecoverable internal error: " ANSI_NORMAL );
writeErr(msg);
writeErr("\n");
abort();
}
void panic(const char * file, int line, const char * func)
{
char buf[512];
int n = snprintf(buf, sizeof(buf), "Unexpected condition in %s at %s:%d", func, file, line);
if (n < 0)
panic("Unexpected condition and could not format error message");
panic(std::string_view(buf, std::min(static_cast<int>(sizeof(buf)), n)));
}
}

View file

@ -273,4 +273,24 @@ using NativeSysError =
*/
void throwExceptionSelfCheck();
/**
* Print a message and abort().
*/
[[noreturn]]
void panic(std::string_view msg);
/**
* Print a basic error message with source position and abort().
* Use the unreachable() macro to call this.
*/
[[noreturn]]
void panic(const char * file, int line, const char * func);
/**
* Print a basic error message with source position and abort().
*
* @note: This assumes that the logger is operational
*/
#define unreachable() (::nix::panic(__FILE__, __LINE__, __func__))
}

View file

@ -63,7 +63,7 @@ std::string_view renderFileIngestionMethod(FileIngestionMethod method)
case FileIngestionMethod::Git:
return "git";
default:
abort();
unreachable();
}
}

View file

@ -53,7 +53,7 @@ void copyRecursive(
throw Error("file '%1%' has an unsupported type", from);
default:
abort();
unreachable();
}
}

View file

@ -201,7 +201,7 @@ std::optional<Mode> convertMode(SourceAccessor::Type type)
case SourceAccessor::tRegular: return Mode::Regular;
case SourceAccessor::tDirectory: return Mode::Directory;
case SourceAccessor::tMisc: return std::nullopt;
default: abort();
default: unreachable();
}
}

View file

@ -25,7 +25,7 @@ static size_t regularHashSize(HashAlgorithm type) {
case HashAlgorithm::SHA256: return sha256HashSize;
case HashAlgorithm::SHA512: return sha512HashSize;
}
abort();
unreachable();
}

View file

@ -189,7 +189,7 @@ struct JSONLogger : Logger {
else if (f.type == Logger::Field::tString)
arr.push_back(f.s);
else
abort();
unreachable();
}
void write(const nlohmann::json & json)

View file

@ -260,7 +260,7 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
});
}
if (!*coro) { abort(); }
if (!*coro) { unreachable(); }
if (!cur.empty()) {
CoroutineContext ctx;
@ -271,12 +271,12 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun)
void finish() override
{
if (!coro) return;
if (!*coro) abort();
if (!*coro) unreachable();
{
CoroutineContext ctx;
(*coro)(true);
}
if (*coro) abort();
if (*coro) unreachable();
}
};
@ -316,7 +316,7 @@ std::unique_ptr<Source> sinkToSource(
});
}
if (!*coro) { eof(); abort(); }
if (!*coro) { eof(); unreachable(); }
if (pos == cur.size()) {
if (!cur.empty()) {

View file

@ -7,6 +7,8 @@
#include <condition_variable>
#include <cassert>
#include "error.hh"
namespace nix {
/**
@ -47,7 +49,7 @@ public:
friend SyncBase;
Lock(SyncBase * s) : s(s), lk(s->mutex) { }
public:
Lock(Lock && l) : s(l.s) { abort(); }
Lock(Lock && l) : s(l.s) { unreachable(); }
Lock(const Lock & l) = delete;
~Lock() { }

View file

@ -40,7 +40,9 @@ public:
#endif
;
auto count = poll(fds, 1, -1);
if (count == -1) abort(); // can't happen
if (count == -1)
unreachable();
/* This shouldn't happen, but can on macOS due to a bug.
See rdar://37550628.

View file

@ -182,7 +182,7 @@ static pid_t doFork(bool allowVfork, ChildWrapperFunction & fun)
#endif
if (pid != 0) return pid;
fun();
abort();
unreachable();
}