JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.08k stars 5.43k forks source link

using - give a hint in error message when there is a typo in package name #38604

Open strickek opened 3 years ago

strickek commented 3 years ago

I think it is a very common mistake with using statements. As package names are case-sensitive, a small typo in name, eg DataFrames: Dataframes, DataFrame, Dataframe, ..., results in an error message:

julia> using Dataframes ERROR: ArgumentError: Package Dataframes not found in current path:

  • Run import Pkg; Pkg.add("Dataframes") to install the Dataframes package.

Stacktrace: [1] require(into::Module, mod::Symbol) @ Base ./loading.jl:874

in the next step the user will do the suggested solution, which will not work:

julia> import Pkg; Pkg.add("Dataframes") Updating registry at ~/.julia/registries/General ERROR: The following package names could not be resolved:

  • Dataframes (not found in project, manifest or registry)

Stacktrace: [1] pkgerror(msg::String) @ Pkg.Types ~/projects/julia/usr/share/julia/stdlib/v1.6/Pkg/src/Types.jl:52 [2] ensure_resolved(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; registry::Bool) @ Pkg.Types ~/projects/julia/usr/share/julia/stdlib/v1.6/Pkg/src/Types.jl:823 ...

I suggest to offer a different error message if there is an installed package with an similar name (in Stdlib or in Project deps), like:

julia> using Dataframes ERROR: ArgumentError: Did you mean DataFrames? Your entry Dataframes is not found in current path. Correct your entry and try again, or run import Pkg; Pkg.add("Dataframes") to install the Dataframes package.

Stacktrace: [1] require(into::Module, mod::Symbol) @ Base ./loading.jl:868

If this is ok, I can offer to open a pull request (have already a first draft).

KristofferC commented 3 years ago

Either, we allow Pkg to install a hook into the error message or we implement the registry parsing ourselves in Base.

vtjnash commented 5 months ago

Pkg does install a hook (via REPL), which seems like it could do this?