Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

infinisil
Copy link
Member

@infinisil infinisil commented Aug 26, 2018

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
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@GrahamcOfBorg GrahamcOfBorg added 6.topic: golang 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: stdenv Standard environment 6.topic: steam 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Aug 26, 2018
@Ericson2314
Copy link
Member

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 ''
Copy link
Member

@Mic92 Mic92 Aug 26, 2018

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.

Copy link
Member

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.

@Profpatsch
Copy link
Member

As @Mic92 said, abort can’t be skipped, while throw is skipped by nix-env. Most changes from lib signal programmer errors, so should stay abort. It doesn’t make sense for packages to use abort however.

@Mic92
Copy link
Member

Mic92 commented Aug 26, 2018

@Profpatsch may be you point to the examples in lib where abort should be used. Because those are not clear to me.

Copy link
Member

@Profpatsch Profpatsch left a 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 ''
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -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
Copy link
Member

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.

@@ -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})";
Copy link
Member

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.

@@ -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})";
Copy link
Member

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.");
Copy link
Member

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."
Copy link
Member

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."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abort

@@ -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} " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Programmer error, abort.

@FRidh
Copy link
Member

FRidh commented Aug 27, 2018

Added "needs: documentation" label because clearly that's the issue here.

@infinisil
Copy link
Member Author

Ah yes, thanks @Profpatsch! Makes sense for those to be aborts as you explained. I undid those ones.

@infinisil infinisil changed the title treewide: abort -> throw (aka aborts are useless, convince me otherwise) treewide: abort -> throw where it makes sense Sep 18, 2018
@infinisil
Copy link
Member Author

Can this be merged like this? This now only changes the aborts that should've been throws from the beginning.

@Mic92
Copy link
Member

Mic92 commented Sep 18, 2018

I am not sure why @edolstra was against the pull request and if those issues are still present.

@infinisil
Copy link
Member Author

Can't be bothered with this

@infinisil infinisil closed this Apr 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: golang 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: stdenv Standard environment 6.topic: steam 8.has: module (update) This PR changes an existing module in `nixos/` 9.needs: documentation 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants