about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorsternenseemann <sternenseemann@systemli.org>2022-01-17 19:12:54 +0100
committersterni <sternenseemann@systemli.org>2022-01-19 00:50:06 +0100
commit48965506a1ac5b0a08a0224551e8604c323691d1 (patch)
treed957fc79688fb02a7c06249e2bbe343ae8faa6da /nixos
parent6733a4dffa4341cd714e97b403f77367d1abf977 (diff)
downloadnixlib-48965506a1ac5b0a08a0224551e8604c323691d1.tar
nixlib-48965506a1ac5b0a08a0224551e8604c323691d1.tar.gz
nixlib-48965506a1ac5b0a08a0224551e8604c323691d1.tar.bz2
nixlib-48965506a1ac5b0a08a0224551e8604c323691d1.tar.lz
nixlib-48965506a1ac5b0a08a0224551e8604c323691d1.tar.xz
nixlib-48965506a1ac5b0a08a0224551e8604c323691d1.tar.zst
nixlib-48965506a1ac5b0a08a0224551e8604c323691d1.zip
lib/asserts: use throw to display message for assertMsg
`assert` has the annoying property that it dumps a lot of code at the
user without the built in capability to display a nicer message. We have
worked around this using `assertMsg` which would *additionally* display
a nice message. We can do even better: By using `throw` we can make
evaluation fail before assert draws its conclusions and prevent it from
displaying the code making up the assert condition, so we get the nicer
message of `throw` and the syntactical convenience of `assert`.

Before:

    nix-repl> python.override { reproducibleBuild = true; stripBytecode = false; }
    trace: Deterministic builds require stripping bytecode.
    error: assertion (((lib).assertMsg  (reproducibleBuild -> stripBytecode))  "Deterministic builds require stripping bytecode.") failed at /home/lukas/src/nix/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix:45:1

After:

    nix-repl> python.override { reproducibleBuild = true; stripBytecode = false; }
    error: Deterministic builds require stripping bytecode.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/doc/manual/from_md/release-notes/rl-2205.section.xml12
-rw-r--r--nixos/doc/manual/release-notes/rl-2205.section.md2
2 files changed, 14 insertions, 0 deletions
diff --git a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
index 34e31b6e505e..ce45b0d79775 100644
--- a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
+++ b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
@@ -408,6 +408,18 @@
           configuration.
         </para>
       </listitem>
+      <listitem>
+        <para>
+          <literal>lib.assertMsg</literal> and
+          <literal>lib.assertOneOf</literal> no longer return
+          <literal>false</literal> if the passed condition is
+          <literal>false</literal>, <literal>throw</literal>ing the
+          given error message instead (which makes the resulting error
+          message less cluttered). This will not impact the behaviour of
+          code using these functions as intended, namely as top-level
+          wrapper for <literal>assert</literal> conditions.
+        </para>
+      </listitem>
     </itemizedlist>
   </section>
   <section xml:id="sec-release-22.05-notable-changes">
diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md
index feac58f05e8b..25b3ada2c563 100644
--- a/nixos/doc/manual/release-notes/rl-2205.section.md
+++ b/nixos/doc/manual/release-notes/rl-2205.section.md
@@ -132,6 +132,8 @@ In addition to numerous new and upgraded packages, this release has the followin
   [settings-style](https://github.com/NixOS/rfcs/blob/master/rfcs/0042-config-option.md)
   configuration.
 
+- `lib.assertMsg` and `lib.assertOneOf` no longer return `false` if the passed condition is `false`, `throw`ing the given error message instead (which makes the resulting error message less cluttered). This will not impact the behaviour of code using these functions as intended, namely as top-level wrapper for `assert` conditions.
+
 <!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
 
 ## Other Notable Changes {#sec-release-22.05-notable-changes}