Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
diagnose.hh
Go to the documentation of this file.
1#pragma once
3
4#include <optional>
5
8#include "nix/util/error.hh"
9#include "nix/util/logging.hh"
10
11namespace nix {
12
16enum struct Diagnose {
29};
30
31NIX_DECLARE_CONFIG_SERIALISER(Diagnose)
32
33
46template<typename F>
47void diagnose(const Setting<Diagnose> & setting, const F & mkError)
48{
49 auto withError = [&](bool fatal, auto && handler) {
50 auto maybeError = mkError(fatal);
51 if (!maybeError)
52 return;
53 auto & info = maybeError->unsafeInfo();
54 // Append the setting name to help users find the right setting
55 info.msg = HintFmt("%s (" ANSI_BOLD "%s" ANSI_NORMAL ")", Uncolored(info.msg.str()), setting.name);
56 maybeError->recalcWhat();
57 handler(std::move(*maybeError));
58 };
59
60 switch (setting.get()) {
62 return;
63 case Diagnose::Warn:
64 withError(false, [](auto && error) { logWarning(error.info()); });
65 return;
66 case Diagnose::Fatal:
67 withError(true, [](auto && error) { throw std::forward<decltype(error)>(error); });
68 return;
69 }
70}
71
72} // namespace nix
Some ANSI escape sequences.
HintFmt(const std::string &literal)
Definition fmt.hh:178
Definition configuration.hh:476
Diagnose
Definition diagnose.hh:16
@ Warn
Definition diagnose.hh:24
@ Fatal
Definition diagnose.hh:28
@ Ignore
Definition diagnose.hh:20
void diagnose(const Setting< Diagnose > &setting, const F &mkError)
Definition diagnose.hh:47
This file defines two main structs/classes used in nix error handling.
Definition fmt.hh:149