Skip to content

Commit 0f9de51

Browse files
explain no reg installed when no reg installed (#4261)
(cherry picked from commit 4d1c6b0)
1 parent d57e20b commit 0f9de51

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/Operations.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,12 @@ function is_all_registered(registries::Vector{Registry.RegistryInstance}, pkgs::
15621562
end
15631563

15641564
function check_registered(registries::Vector{Registry.RegistryInstance}, pkgs::Vector{PackageSpec})
1565+
if isempty(registries) && !isempty(pkgs)
1566+
registry_pkgs = filter(tracking_registered_version, pkgs)
1567+
if !isempty(registry_pkgs)
1568+
pkgerror("no registries have been installed. Cannot resolve the following packages:\n$(join(map(pkg -> " " * err_rep(pkg), registry_pkgs), "\n"))")
1569+
end
1570+
end
15651571
pkg = is_all_registered(registries, pkgs)
15661572
if pkg isa PackageSpec
15671573
pkgerror("expected package $(err_rep(pkg)) to be registered")

test/pkg.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,4 +1055,39 @@ end
10551055
Pkg.activate(prev_project)
10561056
end
10571057

1058+
@testset "check_registered error paths" begin
1059+
# Test the "no registries have been installed" error path
1060+
isolate(loaded_depot=false, linked_reg=false) do
1061+
with_temp_env() do
1062+
# Ensure we have no registries available
1063+
@test isempty(Pkg.Registry.reachable_registries())
1064+
1065+
# Should install General registry automatically
1066+
Pkg.add("Example")
1067+
1068+
Pkg.Registry.rm("General")
1069+
@test isempty(Pkg.Registry.reachable_registries())
1070+
1071+
@test_throws r"no registries have been installed\. Cannot resolve the following packages:" begin
1072+
Pkg.resolve()
1073+
end
1074+
end
1075+
end
1076+
1077+
# Test the "expected package to be registered" error path with a custom unregistered package
1078+
isolate(loaded_depot=true) do; mktempdir() do tempdir
1079+
with_temp_env() do
1080+
# Create a fake package with a manifest that references an unregistered UUID
1081+
fake_pkg_path = copy_test_package(tempdir, "UnregisteredUUID")
1082+
Pkg.activate(fake_pkg_path)
1083+
1084+
# This should fail with "expected package to be registered" error
1085+
@test_throws r"expected package.*to be registered" begin
1086+
Pkg.add("JSON") # This will fail because Example UUID in manifest is unregistered
1087+
end
1088+
end
1089+
end
1090+
end
1091+
end
1092+
10581093
end # module

0 commit comments

Comments
 (0)