Error handling: Difference between revisions
imported>Pogobanane mNo edit summary |
m Fix link "Nix manual: Assertions" |
||
(One intermediate revision by one other user not shown) | |||
Line 8: | Line 8: | ||
lib.warn "This is a sample warning message." | lib.warn "This is a sample warning message." | ||
{ | { | ||
config.warnings = | config.warnings = ( | ||
# Some NixOS module: throw error, if services.foo.bar == true | # Some NixOS module: throw error, if services.foo.bar == true | ||
lib.optionals config.services.foo.bar "This is also a sample warning message, but invoked differently." | |||
); | |||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Line 19: | Line 19: | ||
The nix language has a construct to help with printing messages. | The nix language has a construct to help with printing messages. | ||
* '''assert''': throw an error (see [https://nixos.org/manual/nix/stable/language/ | * '''assert''': throw an error (see [https://nixos.org/manual/nix/stable/language/syntax.html?highlight=assert#assertions Nix manual: Assertions]) | ||
The nix language also comes with some related [https://nixos.org/manual/nix/stable/language/builtins.html builtin functions]: | The nix language also comes with some related [https://nixos.org/manual/nix/stable/language/builtins.html builtin functions]: |