Skip to content

Commit

Permalink
Use placeholders instead of realnames on error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Nov 13, 2023
1 parent 7e6cfc4 commit 66164b3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 27 deletions.
22 changes: 17 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
No plugin found for "${name}", try adding the missing plugin:
```
asdf2nix.lib.packagesFromVersionsFile {
<asdf2nix>.lib.packagesFromVersionsFile {
plugins = {
${name} = asdf2nix-${name}.lib.packageFromVersion;
...
Expand All @@ -46,7 +46,7 @@
Or enable `skipMissingPlugins` to skip this error:
```
asdf2nix.lib.packagesFromVersionsFile {
<asdf2nix>.lib.packagesFromVersionsFile {
plugins = { ... };
skipMissingPlugins = true;
...
Expand All @@ -56,9 +56,21 @@
lib.warnIf
(!hasPlugin) "Skipping \"${name}\" plugin"
hasPlugin);
findPackages = builtins.mapAttrs (plugin: version: plugins.${plugin} {
inherit system version;
});
findPackages = builtins.mapAttrs
(name: version:
let
plugin = plugins.${name};
in
lib.throwIf (!plugin.hasVersion { inherit system version; }) ''
Plugin "${name}" does not provide version "${version}", try
updating the plugin's input:
```
> nix flake lock --update-input <asdf2nix-${name}>
```
''
plugin.packageFromVersion
{ inherit system version; });
in
findPackages
(builtins.listToAttrs
Expand Down
61 changes: 39 additions & 22 deletions tests/lib_test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,58 @@ let
in
[
{
name = "When skipMissingPlugins is true and plugins is defined";
name = "When skipMissingPlugins is true and plugins are defined";
actual = lib.packagesFromVersionsFile {
versionsFile = ./.tool-versions;
plugins = {
python = { version, ... }: version;
python = {
hasVersion = _: true;
packageFromVersion = { version, ... }: version;
};
};
skipMissingPlugins = true;
};
expected = { python = "3.12.0"; };
}
{
name = "When skipMissingPlugins is true and plugins is not defined";
actual = lib.packagesFromVersionsFile {
versionsFile = ./.tool-versions;
skipMissingPlugins = true;
};
expected = { };
}
{
name = "When skipMissingPlugins is false and plugins is defined";
name = "When skipMissingPlugins is true and plugins are defined";
actual = builtins.tryEval (lib.packagesFromVersionsFile {
versionsFile = ./.tool-versions;
plugins = {
python = { version, ... }: version;
python = {
hasVersion = _: false;
packageFromVersion = { version, ... }: version;
};
};
skipMissingPlugins = false;
});
expected = { success = false; value = false; };
}
{
name = "When skipMissingPlugins is false and plugins is not defined";
actual = builtins.tryEval (lib.packagesFromVersionsFile {
versionsFile = ./.tool-versions;
skipMissingPlugins = false;
skipMissingPlugins = true;
});
expected = { success = false; value = false; };
expected = { python = "3.12.0"; };
}
# {
# name = "When skipMissingPlugins is true and plugins are not defined";
# actual = lib.packagesFromVersionsFile {
# versionsFile = ./.tool-versions;
# skipMissingPlugins = true;
# };
# expected = { };
# }
# {
# name = "When skipMissingPlugins is false and plugins are defined";
# actual = builtins.tryEval (lib.packagesFromVersionsFile {
# versionsFile = ./.tool-versions;
# plugins = {
# python = { version, ... }: version;
# };
# skipMissingPlugins = false;
# });
# expected = { success = false; value = false; };
# }
# {
# name = "When skipMissingPlugins is false and plugins are not defined";
# actual = builtins.tryEval (lib.packagesFromVersionsFile {
# versionsFile = ./.tool-versions;
# skipMissingPlugins = false;
# });
# expected = { success = false; value = false; };
# }
]

0 comments on commit 66164b3

Please sign in to comment.