diff --git a/base/loading.jl b/base/loading.jl index 0e2c13912a7de..453024d0686d7 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1050,6 +1050,7 @@ const pkgorigins = Dict{PkgId,PkgOrigin}() function require(uuidkey::PkgId) @lock require_lock begin + just_loaded_pkg = false if !root_module_exists(uuidkey) cachefile = _require(uuidkey) if cachefile !== nothing @@ -1059,6 +1060,11 @@ function require(uuidkey::PkgId) for callback in package_callbacks invokelatest(callback, uuidkey) end + just_loaded_pkg = true + end + if just_loaded_pkg && !root_module_exists(uuidkey) + error("package `$(uuidkey.name)` did not define the expected \ + module `$(uuidkey.name)`, check for typos in package module name") end return root_module(uuidkey) end diff --git a/test/loading.jl b/test/loading.jl index c4cc23575e8d0..4391994830b89 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -745,3 +745,17 @@ end @test Base.get_deps(raw_manifest) == deps end end + +@testset "error message loading pkg bad module name" begin + mktempdir() do tmp + old_loadpath = copy(LOAD_PATH) + try + push!(LOAD_PATH, tmp) + write(joinpath(tmp, "BadCase.jl"), "module badcase end") + @test_throws ErrorException("package `BadCase` did not define the expected module `BadCase`, \ + check for typos in package module name") (@eval using BadCase) + finally + copy!(LOAD_PATH, old_loadpath) + end + end +end