mirror of
https://github.com/NixOS/nix.git
synced 2025-12-03 07:31:00 +01:00
feat(libstore): make cycle errors more verbose
Co-Authored-By: Milan Hauth <milahu@gmail.com>
This commit is contained in:
parent
bef3c37cb2
commit
d44c8c8b69
6 changed files with 574 additions and 42 deletions
|
|
@ -83,6 +83,8 @@ rec {
|
|||
'';
|
||||
};
|
||||
|
||||
# Test for cycle detection with detailed error messages
|
||||
# This creates multiple cycles: a→b→c→a and a→c→b→a
|
||||
cyclic =
|
||||
(mkDerivation {
|
||||
name = "cyclic-outputs";
|
||||
|
|
@ -92,10 +94,22 @@ rec {
|
|||
"c"
|
||||
];
|
||||
builder = builtins.toFile "builder.sh" ''
|
||||
mkdir $a $b $c
|
||||
echo $a > $b/foo
|
||||
echo $b > $c/bar
|
||||
echo $c > $a/baz
|
||||
mkdir -p $a/subdir $b/subdir $c/subdir
|
||||
|
||||
# First cycle: a → b → c → a
|
||||
echo "$b/subdir/b-to-c" > $a/subdir/a-to-b
|
||||
echo "$c/subdir/c-to-a" > $b/subdir/b-to-c
|
||||
echo "$a/subdir/a-to-b" > $c/subdir/c-to-a
|
||||
|
||||
# Second cycle: a → c → b → a
|
||||
echo "$c/subdir/c-to-b-2" > $a/subdir/a-to-c-2
|
||||
echo "$b/subdir/b-to-a-2" > $c/subdir/c-to-b-2
|
||||
echo "$a/subdir/a-to-c-2" > $b/subdir/b-to-a-2
|
||||
|
||||
# Non-cyclic reference (just for complexity)
|
||||
echo "non-cyclic-data" > $a/data
|
||||
echo "non-cyclic-data" > $b/data
|
||||
echo "non-cyclic-data" > $c/data
|
||||
'';
|
||||
}).a;
|
||||
|
||||
|
|
|
|||
|
|
@ -91,9 +91,22 @@ nix-build multiple-outputs.nix -A a.first --no-out-link
|
|||
|
||||
# Cyclic outputs should be rejected.
|
||||
echo "building cyclic..."
|
||||
if nix-build multiple-outputs.nix -A cyclic --no-out-link; then
|
||||
if cyclicOutput=$(nix-build multiple-outputs.nix -A cyclic --no-out-link 2>&1); then
|
||||
echo "Cyclic outputs incorrectly accepted!"
|
||||
exit 1
|
||||
else
|
||||
echo "Cyclic outputs correctly rejected"
|
||||
# Verify error message mentions cycles
|
||||
echo "$cyclicOutput" | grepQuiet "cycle"
|
||||
|
||||
# Enhanced cycle error messages were added in 2.33
|
||||
if isDaemonNewer "2.33"; then
|
||||
echo "$cyclicOutput" | grepQuiet "Detailed cycle analysis"
|
||||
echo "$cyclicOutput" | grepQuiet "Cycle 1:"
|
||||
# The error should mention actual file paths with subdirectories
|
||||
echo "$cyclicOutput" | grepQuiet "subdir"
|
||||
echo "Enhanced cycle error messages verified"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Do a GC. This should leave an empty store.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue