Nix
2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Toggle main menu visibility
Loading...
Searching...
No Matches
diagnose.hh
Go to the documentation of this file.
1
#pragma once
3
4
#include <optional>
5
6
#include "
nix/util/ansicolor.hh
"
7
#include "
nix/util/configuration.hh
"
8
#include "
nix/util/error.hh
"
9
#include "
nix/util/logging.hh
"
10
11
namespace
nix {
12
16
enum struct
Diagnose
{
20
Ignore
,
24
Warn
,
28
Fatal
,
29
};
30
31
NIX_DECLARE_CONFIG_SERIALISER(Diagnose)
32
33
46
template
<
typename
F>
47
void
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()) {
61
case
Diagnose::Ignore
:
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
ansicolor.hh
Some ANSI escape sequences.
nix::HintFmt::HintFmt
HintFmt(const std::string &literal)
Definition
fmt.hh:178
nix::Setting
Definition
configuration.hh:476
configuration.hh
nix::Diagnose
Diagnose
Definition
diagnose.hh:16
nix::Diagnose::Warn
@ Warn
Definition
diagnose.hh:24
nix::Diagnose::Fatal
@ Fatal
Definition
diagnose.hh:28
nix::Diagnose::Ignore
@ Ignore
Definition
diagnose.hh:20
nix::diagnose
void diagnose(const Setting< Diagnose > &setting, const F &mkError)
Definition
diagnose.hh:47
error.hh
This file defines two main structs/classes used in nix error handling.
logging.hh
nix::Uncolored
Definition
fmt.hh:149
libexpr
include
nix
expr
diagnose.hh
Generated by
1.18.0