-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
treewide: abort -> throw where it makes sense #45637
Conversation
Yeah I 've never seen any consistency in one or the other. I assume people use one cause they didn't know of the other. |
default.nix
Outdated
@@ -2,7 +2,7 @@ let requiredVersion = import ./lib/minver.nix; in | |||
|
|||
if ! builtins ? nixVersion || builtins.compareVersions requiredVersion builtins.nixVersion == 1 then | |||
|
|||
abort '' | |||
throw '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this maybe a special case? Some commands like nix-env -qa
will silently ignore throw
as it issues an assertion error while abort
will result in an evaluation error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this should stay abort
.
As @Mic92 said, |
@Profpatsch may be you point to the examples in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented on the first few changes, it looks to me like nearly all of these are programmer errors that should abort the evaluation whenever they happen (not skippable, like with throw
).
So I’m against this change.
default.nix
Outdated
@@ -2,7 +2,7 @@ let requiredVersion = import ./lib/minver.nix; in | |||
|
|||
if ! builtins ? nixVersion || builtins.compareVersions requiredVersion builtins.nixVersion == 1 then | |||
|
|||
abort '' | |||
throw '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this should stay abort
.
lib/attrsets.nix
Outdated
@@ -72,7 +72,7 @@ rec { | |||
*/ | |||
getAttrFromPath = attrPath: set: | |||
let errorMsg = "cannot find attribute `" + concatStringsSep "." attrPath + "'"; | |||
in attrByPath attrPath (abort errorMsg) set; | |||
in attrByPath attrPath (throw errorMsg) set; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
lib/generators.nix
Outdated
@@ -31,7 +31,7 @@ rec { | |||
* suitable for bash scripts but not much else. | |||
*/ | |||
mkValueStringDefault = {}: v: with builtins; | |||
let err = t: v: abort | |||
let err = t: v: throw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abort
, is a programmer error.
lib/generators.nix
Outdated
@@ -171,7 +171,7 @@ rec { | |||
fna); | |||
in if fna == {} then "<λ>" | |||
else "<λ:{${showFnas}}>" | |||
else abort "generators.toPretty: should never happen (v = ${v})"; | |||
else throw "generators.toPretty: should never happen (v = ${v})"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abort
, is a failed pattern match and thus a programmer error.
lib/generators.nix
Outdated
@@ -184,7 +184,7 @@ rec { | |||
if isList x then list ind x else | |||
if isAttrs x then attrs ind x else | |||
if isFloat x then float ind x else | |||
abort "generators.toPlist: should never happen (v = ${v})"; | |||
throw "generators.toPlist: should never happen (v = ${v})"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above
lib/modules.nix
Outdated
@@ -671,7 +671,7 @@ rec { | |||
let | |||
fromOpt = getAttrFromPath from options; | |||
toOf = attrByPath to | |||
(abort "Renaming error: option `${showOption to}' does not exist."); | |||
(throw "Renaming error: option `${showOption to}' does not exist."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also a programmer error, abort
.
lib/options.nix
Outdated
@@ -60,14 +60,14 @@ rec { | |||
else throw "Cannot merge definitions of `${showOption loc}' given in ${showFiles (getFiles defs)}."; | |||
|
|||
mergeOneOption = loc: defs: | |||
if defs == [] then abort "This case should never happen." | |||
if defs == [] then throw "This case should never happen." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abort
lib/options.nix
Outdated
else if length defs != 1 then | ||
throw "The unique option `${showOption loc}' is defined multiple times, in ${showFiles (getFiles defs)}." | ||
else (head defs).value; | ||
|
||
/* "Merge" option definitions by checking that they all have the same value. */ | ||
mergeEqualOption = loc: defs: | ||
if defs == [] then abort "This case should never happen." | ||
if defs == [] then throw "This case should never happen." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abort
nixos/lib/testing.nix
Outdated
@@ -91,7 +91,7 @@ in rec { | |||
|
|||
testDriverName = with builtins; | |||
if testNameLen > maxTestNameLen then | |||
abort ("The name of the test '${name}' must not be longer than ${toString maxTestNameLen} " + | |||
throw ("The name of the test '${name}' must not be longer than ${toString maxTestNameLen} " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Programmer error, abort
.
Added |
465aa0e
to
49105db
Compare
Ah yes, thanks @Profpatsch! Makes sense for those to be aborts as you explained. I undid those ones. |
Can this be merged like this? This now only changes the |
I am not sure why @edolstra was against the pull request and if those issues are still present. |
Can't be bothered with this |
Motivation for this change
I don't really care about this getting merged, but I'd like to find out whether there's any reason for using aborts. Please let me know if you have any valid use case, because I couldn't find any. I also asked many people but nobody had one.
I have NOT tested this in any way, let me know if this breaks anything, which might just be a reason for having aborts then.
Note that I'm looking for actual use cases, not theoretical ones.
Ping @Profpatsch
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)