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

Display better error message when evaling an attr set #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions nixpkgs_review/nix/evalAttrs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,35 @@
with builtins;
let
pkgs = import <nixpkgs> { config = { checkMeta = true; allowUnfree = true; inherit allowAliases; }; };
lib = pkgs.lib;
inherit (pkgs) lib;

attrs = fromJSON (readFile attr-json);
getProperties = name: let
attrPath = lib.splitString "." name;
pkg = lib.attrByPath attrPath null pkgs;
maybePath = builtins.tryEval "${pkg}";
in rec {
exists = lib.hasAttrByPath attrPath pkgs;
broken = !exists || !maybePath.success;
path = if !broken then maybePath.value else null;
drvPath = if !broken then pkg.drvPath else null;
};
getProperties = name:
let
attrPath = lib.splitString "." name;
pkg = lib.attrByPath attrPath null pkgs;
debugAttr = attr: lib.concatStringsSep " " (lib.mapAttrsToList
Copy link
Owner

Choose a reason for hiding this comment

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

What is the goal of function i.e. what cases are you trying to debug?

Could it be replaced by lib.generators.toPretty { allowPrettyValues = true; }?

(name: value: "${name}=${value}")
(lib.mapAttrs
(name: value:
if (isAttrs value && lib.hasAttr "outPath" value) then
value.outPath
else
"")
attr
)
);
maybePath =
if lib.strings.isCoercibleToString pkg then
tryEval "${pkg}"
else
throw "Tried building attr set with the following content: ${debugAttr pkg}";
Copy link
Owner

@Mic92 Mic92 Nov 27, 2021

Choose a reason for hiding this comment

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

Suggested change
throw "Tried building attr set with the following content: ${debugAttr pkg}";
throw "Cannot build attr set `${name}` with the following content:\n${debugAttr pkg}";

in
rec {
exists = lib.hasAttrByPath attrPath pkgs;
broken = !exists || !maybePath.success;
path = if !broken then maybePath.value else null;
drvPath = if !broken then pkg.drvPath else null;
};
in
pkgs.lib.genAttrs attrs getProperties
pkgs.lib.genAttrs attrs getProperties