on iko/ghcjs-patch-master help sign in
haskell.nix: Improve compiler version mismatch error (#1269)

Nix's assert statements reproduce the assertion almost verbatim in an error message, this makes for fairly inscrutable errors. I've tried here to improve the error message by introducing local names (these could create some confusion because of shadowing if similar names are introduced in another scope later) and adding a trace messages using `lib.assertMsg`. Fixes #1249

commitcd9beb4ef5441de71cf0df1ae8914213c7d4ade3 authortoonn <toonn@toonn.io> dateMon 18 Oct 2021, 03:06 (5 years ago) parentf51f24f
1 file changed+10−2
overlays/haskell.nix+10−2
overlays/haskell.nix+10−2
@@ -147,10 +147,18 @@ final: prev: {
147147 else ((plan-pkgs.extras hackage).compiler or (plan-pkgs.pkgs hackage).compiler).nix-name;
148148 pkg-def = excludeBootPackages compiler-nix-name plan-pkgs.pkgs;
149149 patchesModule = ghcHackagePatches.${compiler-nix-name'} or {};
150+ package.compiler-nix-name.version = final.buildPackages.haskell-nix.compiler.${compiler-nix-name'}.version;
151+ plan.compiler-nix-name.version = final.buildPackages.haskell-nix.compiler.${(plan-pkgs.pkgs hackage).compiler.nix-name}.version;
152+ withMsg = final.lib.assertMsg;
150153 in
151154 # Check that the GHC version of the selected compiler matches the one of the plan
152− assert (final.buildPackages.haskell-nix.compiler.${compiler-nix-name'}.version
153− == final.buildPackages.haskell-nix.compiler.${(plan-pkgs.pkgs hackage).compiler.nix-name}.version);
155+ assert (withMsg
156+ (package.compiler-nix-name.version
157+ == plan.compiler-nix-name.version)
158+ ''
159+ The compiler versions for the package and the plan don't match.
160+ Make sure you didn't forget to update plan-sha256.''
161+ );
154162 mkPkgSet {
155163 inherit pkg-def;
156164 pkg-def-extras = [ plan-pkgs.extras