Skip to content

Commit

Permalink
Merge pull request #27534 from JuliaLang/sk/better-load-errors
Browse files Browse the repository at this point in the history
code loading: more helpful error messages
  • Loading branch information
StefanKarpinski authored Jun 12, 2018
2 parents 83ce7ba + d2306d9 commit 89c86c1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
26 changes: 22 additions & 4 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,23 @@ For more details regarding code loading, see the manual.
function require(into::Module, mod::Symbol)
uuidkey = identify_package(into, String(mod))
# Core.println("require($(PkgId(into)), $mod) -> $uuidkey")
uuidkey === nothing &&
throw(ArgumentError("Module $mod not found in current path.\nRun `Pkg.add(\"$mod\")` to install the $mod package."))
if uuidkey === nothing
where = PkgId(into)
if where.uuid === nothing
throw(ArgumentError("""
Package $mod not found in current path:
- Run `Pkg.add($(repr(String(mod))))` to install the $mod package.
"""))
else
throw(ArgumentError("""
Package $(where.name) does not have $mod in its dependencies:
- If you have $(where.name) checked out for development and have
added $mod as a dependency but haven't updated your primary
environment's manifest file, try `Pkg.resolve()`.
- Otherwise you may need to report an issue with $(where.name).
"""))
end
end
if _track_dependencies[]
push!(_require_dependencies, (into, binpack(uuidkey), 0.0))
end
Expand Down Expand Up @@ -947,7 +962,10 @@ function _require(pkg::PkgId)
name = pkg.name
path = locate_package(pkg)
if path === nothing
throw(ArgumentError("Module $name not found in current path.\nRun `Pkg.add(\"$name\")` to install the $name package."))
throw(ArgumentError("""
Package $pkg is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
"""))
end

# attempt to load the module file via the precompile cache locations
Expand Down Expand Up @@ -1179,7 +1197,7 @@ function compilecache(pkg::PkgId)
# decide where to get the source file from
name = pkg.name
path = locate_package(pkg)
path === nothing && throw(ArgumentError("$name not found in path"))
path === nothing && throw(ArgumentError("$pkg not found during precompilation"))
# decide where to put the resulting cache file
cachefile = abspath(DEPOT_PATH[1], cache_file_entry(pkg))
cachepath = dirname(cachefile)
Expand Down
3 changes: 1 addition & 2 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ let
:LibGit2,
:Logging,
:Sockets,

:Printf,
:Profile,
:Dates,
Expand All @@ -526,9 +525,9 @@ let
:SuiteSparse,
:SharedArrays,
:Distributed,
:Pkg,
:Test,
:REPL,
:Pkg,
]

maxlen = maximum(textwidth.(string.(stdlibs)))
Expand Down
3 changes: 2 additions & 1 deletion stdlib/InteractiveUtils/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[deps]
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
OldPkg = "fe1c5a76-5840-53d2-82f9-288dd83ce2ce"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
OldPkg = "fe1c5a76-5840-53d2-82f9-288dd83ce2ce"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
4 changes: 2 additions & 2 deletions stdlib/InteractiveUtils/src/InteractiveUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module InteractiveUtils

export apropos, edit, less, code_warntype, code_llvm, code_native, methodswith, varinfo,
versioninfo, subtypes, peakflops, @which, @edit, @less, @functionloc, @code_warntype,
@code_typed, @code_lowered, @code_llvm, @code_native
@code_typed, @code_lowered, @code_llvm, @code_native, Pkg

import Base.Docs.apropos

Expand All @@ -15,7 +15,7 @@ using Base: unwrap_unionall, rewrap_unionall, isdeprecated, Bottom, show_expr_ty

using Markdown
using LinearAlgebra # for peakflops
import OldPkg
import Pkg, OldPkg

include("editless.jl")
include("codeview.jl")
Expand Down
1 change: 1 addition & 0 deletions stdlib/Pkg/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
return
end

resolve() = up(level=UPLEVEL_FIXED)

pin(pkg::Union{String, PackageSpec}; kwargs...) = pin([pkg]; kwargs...)
pin(pkgs::Vector{String}; kwargs...) = pin([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Pkg/src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ include("Operations.jl")
include("API.jl")
include("REPLMode.jl")

import .API: add, rm, up, test, gc, init, build, installed, pin, free, checkout, develop, generate, instantiate
import .API: add, rm, up, test, gc, init, build, installed, pin, free, checkout, develop, generate, instantiate, resolve
import .Display: status
const update = up
# legacy CI script support
Expand Down
8 changes: 1 addition & 7 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ let exename = `$(Base.julia_cmd()) --sysimage-native-code=yes --startup-file=no`
# make sure this is a non-fatal error and the REPL still loads
@test v[1]
@test isempty(v[2])
@test startswith(v[3], """
┌ Warning: Failed to insert InteractiveUtils into module Main
│ exception =
│ ArgumentError: Module InteractiveUtils not found in current path.
│ Run `Pkg.add("InteractiveUtils")` to install the InteractiveUtils package.
│ Stacktrace:
""")
@test startswith(v[3], "┌ Warning: Failed to insert InteractiveUtils into module Main\n")
end
for nc in ("0", "-2", "x", "2x", " ")
v = readchomperrors(setenv(`$exename -i -E 'Sys.CPU_CORES'`, "JULIA_CPU_CORES" => nc))
Expand Down

0 comments on commit 89c86c1

Please sign in to comment.