From 2221cbb4aaea3ecbda2d4497d2121ed28a4f0bf5 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Tue, 26 May 2026 13:22:22 -0400 Subject: [PATCH] lib.lists: remove assertMsg usage assertMsg sends our error message through a function call, even if the error condition doesn't trigger. This requires a lot of thunk allocation that can be easily avoided. --- lib/lists.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/lists.nix b/lib/lists.nix index a5ee7c5a880d..e2e24244ff28 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -1848,7 +1848,7 @@ rec { */ last = list: - assert lib.assertMsg (list != [ ]) "lists.last: list must not be empty!"; + assert list != [ ] || throw "lists.last: list must not be empty!"; elemAt list (length list - 1); /** @@ -1881,7 +1881,7 @@ rec { */ init = list: - assert lib.assertMsg (list != [ ]) "lists.init: list must not be empty!"; + assert list != [ ] || throw "lists.init: list must not be empty!"; genList (elemAt list) (length list - 1); /** @@ -2157,7 +2157,8 @@ rec { */ replaceElemAt = list: idx: newElem: - assert lib.assertMsg (idx >= 0 && idx < length list) - "'lists.replaceElemAt' called with index ${toString idx} on a list of size ${toString (length list)}"; + assert + idx >= 0 && idx < length list + || throw "'lists.replaceElemAt' called with index ${toString idx} on a list of size ${toString (length list)}"; genList (i: if i == idx then newElem else elemAt list i) (length list); }