diff --git a/src/Operations.jl b/src/Operations.jl index 245a910d63..e434f59d56 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -1594,7 +1594,24 @@ function check_registered(registries::Vector{Registry.RegistryInstance}, pkgs::V end pkg = is_all_registered(registries, pkgs) if pkg isa PackageSpec - pkgerror("expected package $(err_rep(pkg)) to be registered") + msg = "expected package $(err_rep(pkg)) to be registered" + # check if the name exists in the registry with a different uuid + if pkg.name !== nothing + reg_uuid = Pair{String, Vector{UUID}}[] + for reg in registries + uuids = Registry.uuids_from_name(reg, pkg.name) + if !isempty(uuids) + push!(reg_uuid, reg.name => uuids) + end + end + if !isempty(reg_uuid) + msg *= "\n You may have provided the wrong UUID for package $(pkg.name).\n Found the following UUIDs for that name:" + for (reg, uuids) in reg_uuid + msg *= "\n - $(join(uuids, ", ")) from registry: $reg" + end + end + end + pkgerror(msg) end return nothing end diff --git a/test/new.jl b/test/new.jl index 0e4b5169cb..acf4ba34cc 100644 --- a/test/new.jl +++ b/test/new.jl @@ -538,7 +538,7 @@ end isolate(loaded_depot=true) do; mktempdir() do tempdir package_path = copy_test_package(tempdir, "UnregisteredUUID") Pkg.activate(package_path) - @test_throws PkgError("expected package `Example [142fd7e7]` to be registered") Pkg.add("JSON") + @test_throws PkgError Pkg.add("JSON") end end # empty git repo (no commits) isolate(loaded_depot=true) do; mktempdir() do tempdir @@ -1536,7 +1536,7 @@ end isolate(loaded_depot=true) do; mktempdir() do tempdir package_path = copy_test_package(tempdir, "UnregisteredUUID") Pkg.activate(package_path) - @test_throws PkgError("expected package `Example [142fd7e7]` to be registered") Pkg.update() + @test_throws PkgError Pkg.update() end end end @@ -1714,7 +1714,7 @@ end isolate(loaded_depot=true) do; mktempdir() do tempdir package_path = copy_test_package(tempdir, "UnregisteredUUID") Pkg.activate(package_path) - @test_throws PkgError("expected package `Example [142fd7e7]` to be registered") Pkg.update() + @test_throws PkgError Pkg.update() end end # package does not exist in the manifest isolate(loaded_depot=true) do diff --git a/test/pkg.jl b/test/pkg.jl index 8271697110..f0e9950ce1 100644 --- a/test/pkg.jl +++ b/test/pkg.jl @@ -207,6 +207,18 @@ temp_pkg_dir() do project_path @testset "package with wrong UUID" begin @test_throws PkgError Pkg.add(PackageSpec(TEST_PKG.name, UUID(UInt128(1)))) + @testset "package with wrong UUID but correct name" begin + try + Pkg.add(PackageSpec(name="Example", uuid=UUID(UInt128(2)))) + catch e + @test e isa PkgError + errstr = sprint(showerror, e) + @test occursin("expected package `Example [00000000]` to be registered", errstr) + @test occursin("You may have provided the wrong UUID for package Example.", errstr) + @test occursin("Found the following UUIDs for that name:", errstr) + @test occursin("- 7876af07-990d-54b4-ab0e-23690620f79a from registry: General", errstr) + end + end # Missing uuid @test_throws PkgError Pkg.add(PackageSpec(uuid = uuid4())) end