Skip to content

improve error message when module of package is not the same as the package #43158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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