Skip to content

Commit

Permalink
treewide: Change unnecessary aborts to throws
Browse files Browse the repository at this point in the history
`throw`s are better because they don't abort evaluation when evaluating the whole set.

Fixes

`error: evaluation aborted with the following error message: 'Unsupported platform: arm64.'` on linux cross from darwin
  • Loading branch information
Artturin committed Dec 6, 2024
1 parent 095f469 commit 8f7e8b0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkgs/applications/networking/cluster/k3s/builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,25 @@ let
s:
mutFirstChar lib.toLower (lib.concatMapStrings (mutFirstChar lib.toUpper) (lib.splitString "-" s));

# finds the images archive for the desired architecture, aborts in case no suitable archive is found
# finds the images archive for the desired architecture, throws in case no suitable archive is found
findImagesArchive =
arch:
let
imagesVersionsNames = builtins.attrNames imagesVersions;
in
lib.findFirst (
n: lib.hasInfix arch n
) (abort "k3s: no airgap images for ${arch} available") imagesVersionsNames;
) (throw "k3s: no airgap images for ${arch} available") imagesVersionsNames;

# a shortcut that provides the images archive for the host platform. Currently only supports
# aarch64 (arm64) and x86_64 (amd64), aborts on other architectures.
# aarch64 (arm64) and x86_64 (amd64), throws on other architectures.
airgapImages = fetchurl (
if stdenv.hostPlatform.isAarch64 then
imagesVersions.${findImagesArchive "arm64"}
else if stdenv.hostPlatform.isx86_64 then
imagesVersions.${findImagesArchive "amd64"}
else
abort "k3s: airgap images cannot be found automatically for architecture ${stdenv.hostPlatform.linuxArch}, consider using an image archive with an explicit architecture."
throw "k3s: airgap images cannot be found automatically for architecture ${stdenv.hostPlatform.linuxArch}, consider using an image archive with an explicit architecture."
);

# so, k3s is a complicated thing to package
Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/de/debase/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ stdenv.mkDerivation rec {
else if stdenv.hostPlatform.isAarch64 then
"arm64"
else
abort "unsupported system: ${stdenv.system}"
throw "unsupported system: ${stdenv.system}"
}"
];

Expand Down
4 changes: 2 additions & 2 deletions pkgs/by-name/ni/nim-unwrapped-2_2/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let
else if isx86_64 then
"amd64"
else
abort "no Nim CPU support known for ${config}";
throw "no Nim CPU support known for ${config}";

parseOs =
platform:
Expand All @@ -72,7 +72,7 @@ let
else if isiOS then
"iOS"
else
abort "no Nim OS support known for ${config}";
throw "no Nim OS support known for ${config}";

parsePlatform = p: {
cpu = parseCpu p;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/by-name/vi/virtual-ans/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ stdenv.mkDerivation rec {
startScript = if stdenv.hostPlatform.isx86_32 then "START_LINUX_X86"
else if stdenv.hostPlatform.isx86_64 then "START_LINUX_X86_64"
#else if stdenv.hostPlatform.isDarwin then "START_MACOS.app" # disabled because I cannot test on Darwin
else abort "Unsupported platform: ${stdenv.hostPlatform.linuxArch}.";
else throw "Unsupported platform: ${stdenv.hostPlatform.linuxArch}.";

linuxExecutable = if stdenv.hostPlatform.isx86_32 then "pixilang_linux_x86"
else if stdenv.hostPlatform.isx86_64 then "pixilang_linux_x86_64"
Expand Down

0 comments on commit 8f7e8b0

Please sign in to comment.