mirror of
https://github.com/NixOS/nix
synced 2025-07-07 10:11:47 +02:00
Improve error messages for invalid derivation names
This commit is contained in:
parent
5f4f789144
commit
7df9d6da65
16 changed files with 145 additions and 16 deletions
26
tests/functional/lang/eval-fail-derivation-name.err.exp
Normal file
26
tests/functional/lang/eval-fail-derivation-name.err.exp
Normal file
|
@ -0,0 +1,26 @@
|
|||
error:
|
||||
… while evaluating the attribute 'outPath'
|
||||
at <nix/derivation-internal.nix>:19:9:
|
||||
18| value = commonAttrs // {
|
||||
19| outPath = builtins.getAttr outputName strict;
|
||||
| ^
|
||||
20| drvPath = strict.drvPath;
|
||||
|
||||
… while calling the 'getAttr' builtin
|
||||
at <nix/derivation-internal.nix>:19:19:
|
||||
18| value = commonAttrs // {
|
||||
19| outPath = builtins.getAttr outputName strict;
|
||||
| ^
|
||||
20| drvPath = strict.drvPath;
|
||||
|
||||
… while calling the 'derivationStrict' builtin
|
||||
at <nix/derivation-internal.nix>:9:12:
|
||||
8|
|
||||
9| strict = derivationStrict drvAttrs;
|
||||
| ^
|
||||
10|
|
||||
|
||||
… while evaluating derivation '~jiggle~'
|
||||
whose name attribute is located at /pwd/lang/eval-fail-derivation-name.nix:2:3
|
||||
|
||||
error: invalid derivation name: name '~jiggle~' contains illegal character '~'. Please pass a different 'name'.
|
5
tests/functional/lang/eval-fail-derivation-name.nix
Normal file
5
tests/functional/lang/eval-fail-derivation-name.nix
Normal file
|
@ -0,0 +1,5 @@
|
|||
derivation {
|
||||
name = "~jiggle~";
|
||||
system = "some-system";
|
||||
builder = "/dontcare";
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while calling the 'fetchurl' builtin
|
||||
at /pwd/lang/eval-fail-fetchurl-baseName-attrs-name.nix:1:1:
|
||||
1| builtins.fetchurl { url = "https://example.com/foo.tar.gz"; name = "~wobble~"; }
|
||||
| ^
|
||||
2|
|
||||
|
||||
error: invalid store path name when fetching URL 'https://example.com/foo.tar.gz': name '~wobble~' contains illegal character '~'. Please change the value for the 'name' attribute passed to 'fetchurl', so that it can create a valid store path.
|
|
@ -0,0 +1 @@
|
|||
builtins.fetchurl { url = "https://example.com/foo.tar.gz"; name = "~wobble~"; }
|
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while calling the 'fetchurl' builtin
|
||||
at /pwd/lang/eval-fail-fetchurl-baseName-attrs.nix:1:1:
|
||||
1| builtins.fetchurl { url = "https://example.com/~wiggle~"; }
|
||||
| ^
|
||||
2|
|
||||
|
||||
error: invalid store path name when fetching URL 'https://example.com/~wiggle~': name '~wiggle~' contains illegal character '~'. Please add a valid 'name' attribute to the argument for 'fetchurl', so that it can create a valid store path.
|
|
@ -0,0 +1 @@
|
|||
builtins.fetchurl { url = "https://example.com/~wiggle~"; }
|
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while calling the 'fetchurl' builtin
|
||||
at /pwd/lang/eval-fail-fetchurl-baseName.nix:1:1:
|
||||
1| builtins.fetchurl "https://example.com/~wiggle~"
|
||||
| ^
|
||||
2|
|
||||
|
||||
error: invalid store path name when fetching URL 'https://example.com/~wiggle~': name '~wiggle~' contains illegal character '~'. Please pass an attribute set with 'url' and 'name' attributes to 'fetchurl', so that it can create a valid store path.
|
1
tests/functional/lang/eval-fail-fetchurl-baseName.nix
Normal file
1
tests/functional/lang/eval-fail-fetchurl-baseName.nix
Normal file
|
@ -0,0 +1 @@
|
|||
builtins.fetchurl "https://example.com/~wiggle~"
|
|
@ -26,10 +26,19 @@ static std::regex nameRegex { std::string { nameRegexStr } };
|
|||
TEST_F(StorePathTest, bad_ ## NAME) { \
|
||||
std::string_view str = \
|
||||
STORE_DIR HASH_PART "-" STR; \
|
||||
ASSERT_THROW( \
|
||||
store->parseStorePath(str), \
|
||||
BadStorePath); \
|
||||
/* ASSERT_THROW generates a duplicate goto label */ \
|
||||
/* A lambda isolates those labels. */ \
|
||||
[&](){ \
|
||||
ASSERT_THROW( \
|
||||
store->parseStorePath(str), \
|
||||
BadStorePath); \
|
||||
}(); \
|
||||
std::string name { STR }; \
|
||||
[&](){ \
|
||||
ASSERT_THROW( \
|
||||
nix::checkName(name), \
|
||||
BadStorePathName); \
|
||||
}(); \
|
||||
EXPECT_FALSE(std::regex_match(name, nameRegex)); \
|
||||
}
|
||||
|
||||
|
@ -54,6 +63,7 @@ TEST_DONT_PARSE(dot_dash_a, ".-a")
|
|||
STORE_DIR HASH_PART "-" STR; \
|
||||
auto p = store->parseStorePath(str); \
|
||||
std::string name { p.name() }; \
|
||||
EXPECT_EQ(p.name(), STR); \
|
||||
EXPECT_TRUE(std::regex_match(name, nameRegex)); \
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue