forked from lix-project/lix
Merge pull request #8109 from oxalica/fix/show-legacy-packages
Catch eval errors in `hasContent`
This commit is contained in:
commit
9e7940e35d
|
@ -1026,6 +1026,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
|||
|
||||
auto visitor2 = visitor.getAttr(attrName);
|
||||
|
||||
try {
|
||||
if ((attrPathS[0] == "apps"
|
||||
|| attrPathS[0] == "checks"
|
||||
|| attrPathS[0] == "devShells"
|
||||
|
@ -1056,6 +1057,12 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
|||
|
||||
// If we don't recognize it, it's probably content
|
||||
return true;
|
||||
} catch (EvalError & e) {
|
||||
// Some attrs may contain errors, eg. legacyPackages of
|
||||
// nixpkgs. We still want to recurse into it, instead of
|
||||
// skipping it at all.
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
std::function<nlohmann::json(
|
||||
|
|
|
@ -64,3 +64,24 @@ in
|
|||
assert show_output == { };
|
||||
true
|
||||
'
|
||||
|
||||
# Test that attributes with errors are handled correctly.
|
||||
# nixpkgs.legacyPackages is a particularly prominent instance of this.
|
||||
cat >flake.nix <<EOF
|
||||
{
|
||||
outputs = inputs: {
|
||||
legacyPackages.$system = {
|
||||
AAAAAASomeThingsFailToEvaluate = throw "nooo";
|
||||
simple = import ./simple.nix;
|
||||
};
|
||||
};
|
||||
}
|
||||
EOF
|
||||
nix flake show --json --legacy --all-systems > show-output.json
|
||||
nix eval --impure --expr '
|
||||
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
|
||||
in
|
||||
assert show_output.legacyPackages.${builtins.currentSystem}.AAAAAASomeThingsFailToEvaluate == { };
|
||||
assert show_output.legacyPackages.${builtins.currentSystem}.simple.name == "simple";
|
||||
true
|
||||
'
|
||||
|
|
Loading…
Reference in a new issue