Skip to content

Commit

Permalink
rename CommandError to PkgError (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Aug 4, 2018
1 parent e804d11 commit eed9ea7
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 133 deletions.
18 changes: 9 additions & 9 deletions stdlib/Pkg/src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include("generate.jl")

function check_package_name(x::String)
if !(occursin(Pkg.REPLMode.name_re, x))
cmderror("$x is not a valid packagename")
pkgerror("$x is not a valid packagename")
end
return PackageSpec(x)
end
Expand All @@ -39,7 +39,7 @@ function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, s
# if julia is passed as a package the solver gets tricked;
# this catches the error early on
any(pkg->(pkg.name == "julia"), pkgs) &&
cmderror("Trying to $mode julia as a package")
pkgerror("Trying to $mode julia as a package")

ctx.preview && preview_info()
if mode == :develop
Expand All @@ -54,7 +54,7 @@ function add_or_develop(ctx::Context, pkgs::Vector{PackageSpec}; mode::Symbol, s
ensure_resolved(ctx.env, pkgs, registry=true)

any(pkg -> Types.collides_with_project(ctx.env, pkg), pkgs) &&
cmderror("Cannot $mode package with the same name or uuid as the project")
pkgerror("Cannot $mode package with the same name or uuid as the project")

Operations.add_or_develop(ctx, pkgs; new_git=new_git)
ctx.preview && preview_info()
Expand Down Expand Up @@ -107,7 +107,7 @@ function update_registry(ctx)
try
GitTools.fetch(repo; refspecs=["+refs/heads/$branch:refs/remotes/origin/$branch"])
catch e
e isa CommandError || rethrow(e)
e isa PkgError || rethrow(e)
push!(errors, (reg, "failed to fetch from repo"))
return
end
Expand Down Expand Up @@ -219,7 +219,7 @@ function free(ctx::Context, pkgs::Vector{PackageSpec}; kwargs...)
for pkg in pkgs
info = manifest_info(ctx.env, pkg.uuid)
if !get(info, "pinned", false) && !(pkg.uuid in uuids_in_registry)
cmderror("cannot free an unpinned package that does not exist in a registry")
pkgerror("cannot free an unpinned package that does not exist in a registry")
end
end
Operations.free(ctx, pkgs)
Expand All @@ -238,7 +238,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false, kwargs...
ctx.preview && preview_info()
if isempty(pkgs)
# TODO: Allow this?
ctx.env.pkg == nothing && cmderror("trying to test unnamed project")
ctx.env.pkg == nothing && pkgerror("trying to test unnamed project")
push!(pkgs, ctx.env.pkg)
end
project_resolve!(ctx.env, pkgs)
Expand Down Expand Up @@ -468,7 +468,7 @@ function precompile(ctx::Context)
sourcepath = Base.locate_package(pkg)
if sourcepath == nothing
# XXX: this isn't supposed to be fatal
cmderror("couldn't find path to $(pkg.name) when trying to precompilie project")
pkgerror("couldn't find path to $(pkg.name) when trying to precompilie project")
end
stale = true
for path_to_try in paths::Vector{String}
Expand Down Expand Up @@ -504,7 +504,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing, kwarg
return
end
if !isfile(ctx.env.manifest_file) && manifest == true
cmderror("manifest at $(ctx.env.manifest_file) does not exist")
pkgerror("manifest at $(ctx.env.manifest_file) does not exist")
end
update_registry(ctx)
urls = Dict{}
Expand Down Expand Up @@ -578,7 +578,7 @@ function activate(path::String; shared::Bool=false)
end
# this disallows names such as "Foo/bar", ".", "..", etc
if basename(abspath(fullpath)) != path
cmderror("not a valid name for a shared environment: $(path)")
pkgerror("not a valid name for a shared environment: $(path)")
end
# unless the shared environment already exists, place it in the first depots
if !isdir(fullpath)
Expand Down
8 changes: 4 additions & 4 deletions stdlib/Pkg/src/GitTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ function clone(url, source_path; header=nothing, kwargs...)
err isa LibGit2.GitError || rethrow(err)
if (err.class == LibGit2.Error.Net && err.code == LibGit2.Error.EINVALIDSPEC) ||
(err.class == LibGit2.Error.Repository && err.code == LibGit2.Error.ENOTFOUND)
Pkg.Types.cmderror("Git repository not found at '$(url)'")
Pkg.Types.pkgerror("Git repository not found at '$(url)'")
else
Pkg.Types.cmderror("failed to clone from $(url), error: $err")
Pkg.Types.pkgerror("failed to clone from $(url), error: $err")
end
finally
print(stdout, "\033[2K") # clear line
Expand Down Expand Up @@ -128,9 +128,9 @@ function fetch(repo::LibGit2.GitRepo, remoteurl=nothing; header=nothing, kwargs.
catch err
err isa LibGit2.GitError || rethrow(err)
if (err.class == LibGit2.Error.Repository && err.code == LibGit2.Error.ERROR)
Pkg.Types.cmderror("Git repository not found at '$(remoteurl)'")
Pkg.Types.pkgerror("Git repository not found at '$(remoteurl)'")
else
Pkg.Types.cmderror("failed to fetch from $(remoteurl), error: $err")
Pkg.Types.pkgerror("failed to fetch from $(remoteurl), error: $err")
end
finally
print(stdout, "\033[2K") # clear line
Expand Down
22 changes: 11 additions & 11 deletions stdlib/Pkg/src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function load_package_data(f::Base.Callable, path::String, versions)
vr = VersionRange(v)
ver in vr || continue
dict = get!(data, ver, Dict{String,Any}())
haskey(dict, key) && cmderror("$ver/$key is duplicated in $path")
haskey(dict, key) && pkgerror("$ver/$key is duplicated in $path")
dict[key] = f(value)
end
end
Expand All @@ -53,7 +53,7 @@ function load_package_data_raw(T::Type, path::String)
for (v, d) in toml, (key, value) in d
vr = VersionRange(v)
dict = get!(data, vr, Dict{String,T}())
haskey(dict, key) && cmderror("$vr/$key is duplicated in $path")
haskey(dict, key) && pkgerror("$vr/$key is duplicated in $path")
dict[key] = T(value)
end
return data
Expand Down Expand Up @@ -106,7 +106,7 @@ function collect_fixed!(ctx::Context, pkgs::Vector{PackageSpec}, uuid_to_name::D

path = project_rel_path(ctx, path)
if !isdir(path)
cmderror("path $(path) for package $(pkg.name) no longer exists. Remove the package or `develop` it at a new path")
pkgerror("path $(path) for package $(pkg.name) no longer exists. Remove the package or `develop` it at a new path")
end

uuid_to_pkg[pkg.uuid] = pkg
Expand Down Expand Up @@ -328,7 +328,7 @@ function resolve_versions!(ctx::Context, pkgs::Vector{PackageSpec})::Dict{UUID,V
proj_compat = Types.project_compatibility(ctx, name)
v = intersect(pkg.version, proj_compat)
if isempty(v)
cmderror(string("for package $(pkg.name) intersection between project compatibility $(proj_compat) ",
pkgerror(string("for package $(pkg.name) intersection between project compatibility $(proj_compat) ",
"and package version $(pkg.version) is empty"))
end
pkg.version = v
Expand Down Expand Up @@ -382,7 +382,7 @@ function version_data!(ctx::Context, pkgs::Vector{PackageSpec})
info = parse_toml(path, "Package.toml")
if haskey(names, uuid)
names[uuid] == info["name"] ||
cmderror("$uuid: name mismatch between registries: ",
pkgerror("$uuid: name mismatch between registries: ",
"$(names[uuid]) vs. $(info["name"])")
else
names[uuid] = info["name"]
Expand Down Expand Up @@ -569,7 +569,7 @@ function apply_versions(ctx::Context, pkgs::Vector{PackageSpec}, hashes::Dict{UU
try
success = install_archive(urls[pkg.uuid], hashes[pkg.uuid], path)
if ctx.use_only_tarballs_for_downloads && !success
cmderror("failed to get tarball from $(urls[pkg.uuid])")
pkgerror("failed to get tarball from $(urls[pkg.uuid])")
end
put!(results, (pkg, success, path))
catch err
Expand All @@ -582,7 +582,7 @@ function apply_versions(ctx::Context, pkgs::Vector{PackageSpec}, hashes::Dict{UU
missed_packages = Tuple{PackageSpec, String}[]
for i in 1:length(pkgs_to_install)
pkg, exc_or_success, bt_or_path = take!(results)
exc_or_success isa Exception && cmderror("Error when installing packages:\n", sprint(Base.showerror, exc_or_success, bt_or_path))
exc_or_success isa Exception && pkgerror("Error when installing packages:\n", sprint(Base.showerror, exc_or_success, bt_or_path))
success, path = exc_or_success, bt_or_path
if success
vstr = pkg.version != nothing ? "v$(pkg.version)" : "[$h]"
Expand Down Expand Up @@ -1021,7 +1021,7 @@ function build_versions(ctx::Context, uuids::Vector{UUID}; might_need_to_resolve
path = project_rel_path(ctx, info["path"])
hash_or_path = path
else
cmderror("Could not find either `git-tree-sha1` or `path` for package $(pkg.name)")
pkgerror("Could not find either `git-tree-sha1` or `path` for package $(pkg.name)")
end
version = v"0.0"
end
Expand Down Expand Up @@ -1257,7 +1257,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false)
elseif pkg.uuid in keys(ctx.stdlibs)
version_path = Types.stdlib_path(pkg.name)
else
cmderror("Could not find either `git-tree-sha1` or `path` for package $(pkg.name)")
pkgerror("Could not find either `git-tree-sha1` or `path` for package $(pkg.name)")
end
end
testfile = joinpath(version_path, "test", "runtests.jl")
Expand All @@ -1268,7 +1268,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false)
push!(testfiles, testfile)
end
if !isempty(missing_runtests)
cmderror(length(missing_runtests) == 1 ? "Package " : "Packages ",
pkgerror(length(missing_runtests) == 1 ? "Package " : "Packages ",
join(missing_runtests, ", "),
" did not provide a `test/runtests.jl` file")
end
Expand Down Expand Up @@ -1313,7 +1313,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec}; coverage=false)
end

if !isempty(pkgs_errored)
cmderror(length(pkgs_errored) == 1 ? "Package " : "Packages ",
pkgerror(length(pkgs_errored) == 1 ? "Package " : "Packages ",
join(pkgs_errored, ", "),
" errored during testing")
end
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 @@ -14,7 +14,7 @@ export UpgradeLevel, UPLEVEL_MAJOR, UPLEVEL_MAJOR, UPLEVEL_MINOR, UPLEVEL_PATCH
depots() = Base.DEPOT_PATH
function depots1()
d = depots()
isempty(d) && cmderror("no depots found in DEPOT_PATH")
isempty(d) && pkgerror("no depots found in DEPOT_PATH")
return d[1]
end

Expand Down
44 changes: 22 additions & 22 deletions stdlib/Pkg/src/REPLMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Base.show(io::IO, opt::Option) = print(io, "--$(opt.val)", opt.argument == nothi

function parse_option(word::AbstractString)::Option
m = match(r"^(?: -([a-z]) | --([a-z]{2,})(?:\s*=\s*(\S*))? )$"ix, word)
m == nothing && cmderror("malformed option: ", repr(word))
m == nothing && pkgerror("malformed option: ", repr(word))
option_name = (m.captures[1] != nothing ? m.captures[1] : m.captures[2])
option_arg = (m.captures[3] == nothing ? nothing : String(m.captures[3]))
return Option(option_name, option_arg)
Expand Down Expand Up @@ -174,7 +174,7 @@ function parse_package(word::AbstractString; add_or_develop=false)::PackageSpec
# Guess it is a url then
return PackageSpec(Types.GitRepo(word))
else
cmderror("`$word` cannot be parsed as a package")
pkgerror("`$word` cannot be parsed as a package")
end
end

Expand Down Expand Up @@ -218,7 +218,7 @@ function Statement(words)::Statement
# meta options
while is_option(word)
push!(statement.meta_options, word)
isempty(words) && cmderror("no command specified")
isempty(words) && pkgerror("no command specified")
word = popfirst!(words)
end
# command
Expand All @@ -229,7 +229,7 @@ function Statement(words)::Statement
super = super_specs["package"]
end
command = get(super, word, nothing)
command !== nothing || cmderror("expected command. instead got [$word]")
command !== nothing || pkgerror("expected command. instead got [$word]")
statement.command = command
# command arguments
for word in words
Expand All @@ -245,7 +245,7 @@ function group_words(words)::Vector{Vector{String}}
x = String[]
for word in words
if word == ";"
isempty(x) ? cmderror("empty statement") : push!(statements, x)
isempty(x) ? pkgerror("empty statement") : push!(statements, x)
x = String[]
else
push!(x, word)
Expand Down Expand Up @@ -300,7 +300,7 @@ function parse_quotes(cmd::String)::Vector{QuotedWord}
end
end
if (in_doublequote || in_singlequote)
cmderror("unterminated quote")
pkgerror("unterminated quote")
else
push_token!(false)
end
Expand Down Expand Up @@ -345,7 +345,7 @@ end
function enforce_argument_order(args::Vector{Token})
prev_arg = nothing
function check_prev_arg(valid_type::DataType, error_message::AbstractString)
prev_arg isa valid_type || cmderror(error_message)
prev_arg isa valid_type || pkgerror(error_message)
end

for arg in args
Expand Down Expand Up @@ -379,11 +379,11 @@ function enforce_arg_spec(raw_args::Vector{String}, class::ArgClass)
class == ARG_ALL && return args

if class == ARG_PKG && has_types(args, [VersionRange, Rev])
cmderror("no versioned packages allowed")
pkgerror("no versioned packages allowed")
elseif class == ARG_REV && has_types(args, [VersionRange])
cmderror("no versioned packages allowed")
pkgerror("no versioned packages allowed")
elseif class == ARG_VERSION && has_types(args, [Rev])
cmderror("no reved packages allowed")
pkgerror("no reved packages allowed")
end
return args
end
Expand Down Expand Up @@ -413,7 +413,7 @@ end
function enforce_arg_count(count::Vector{Int}, args::PkgArguments)
isempty(count) && return
length(args) in count ||
cmderror("Wrong number of arguments")
pkgerror("Wrong number of arguments")
end

function enforce_args(raw_args::Vector{String}, spec::ArgSpec, cmd_spec::CommandSpec)::PkgArguments
Expand All @@ -433,13 +433,13 @@ function enforce_option(option::String, specs::Dict{String,OptionSpec})::Option
opt = parse_option(option)
spec = get(specs, opt.val, nothing)
spec !== nothing ||
cmderror("option '$(opt.val)' is not a valid option")
pkgerror("option '$(opt.val)' is not a valid option")
if spec.is_switch
opt.argument === nothing ||
cmderror("option '$(opt.val)' does not take an argument, but '$(opt.argument)' given")
pkgerror("option '$(opt.val)' does not take an argument, but '$(opt.argument)' given")
else # option takes an argument
opt.argument !== nothing ||
cmderror("option '$(opt.val)' expects an argument, but no argument given")
pkgerror("option '$(opt.val)' expects an argument, but no argument given")
end
return opt
end
Expand All @@ -449,7 +449,7 @@ function enforce_meta_options(options::Vector{String}, specs::Dict{String,Option
return map(options) do opt
tok = enforce_option(opt, specs)
tok.val in meta_opt_names ||
cmderror("option '$opt' is not a valid meta option.")
pkgerror("option '$opt' is not a valid meta option.")
#TODO hint that maybe they intended to use it as a command option
return tok
end
Expand All @@ -465,12 +465,12 @@ function enforce_opts(options::Vector{String}, specs::Dict{String,OptionSpec})::
for opt in toks
# valid option
opt.val in keys(specs) ||
cmderror("option '$(opt.val)' is not supported")
pkgerror("option '$(opt.val)' is not supported")
# conflicting options
key = get_key(opt)
if key in unique_keys
conflicting = filter(opt->get_key(opt) == key, toks)
cmderror("Conflicting options: $conflicting")
pkgerror("Conflicting options: $conflicting")
else
push!(unique_keys, key)
end
Expand Down Expand Up @@ -505,7 +505,7 @@ function do_cmd(repl::REPL.AbstractREPL, input::String; do_rethrow=false)
if do_rethrow
rethrow(err)
end
if err isa CommandError || err isa ResolverError
if err isa PkgError || err isa ResolverError
Base.display_error(repl.t.err_stream, ErrorException(sprint(showerror, err)), Ptr{Nothing}[])
else
Base.display_error(repl.t.err_stream, err, Base.catch_backtrace())
Expand All @@ -525,7 +525,7 @@ function do_cmd!(command::PkgCommand, repl)
cmd = command.arguments[1]
cmd_spec = get(command_specs, cmd, nothing)
cmd_spec === nothing &&
cmderror("'$cmd' is not a valid command")
pkgerror("'$cmd' is not a valid command")
spec = cmd_spec
command = PkgCommand([], cmd, [], PackageSpec[])
end
Expand All @@ -550,9 +550,9 @@ function do_help!(command::PkgCommand, repl::REPL.AbstractREPL)
for arg in command.arguments
spec = get(command_specs, arg, nothing)
spec === nothing &&
cmderror("'$arg' does not name a command")
pkgerror("'$arg' does not name a command")
spec.help === nothing &&
cmderror("Sorry, I don't have any help for the `$arg` command.")
pkgerror("Sorry, I don't have any help for the `$arg` command.")
isempty(help_md.content) ||
push!(help_md.content, md"---")
push!(help_md.content, spec.help)
Expand Down Expand Up @@ -617,7 +617,7 @@ function do_pin!(ctx::APIOptions, args::PkgArguments, api_opts::APIOptions)
for arg in args
# TODO not sure this is correct
if arg.version.ranges[1].lower != arg.version.ranges[1].upper
cmderror("pinning a package requires a single version, not a versionrange")
pkgerror("pinning a package requires a single version, not a versionrange")
end
end
API.pin(Context!(ctx), args; collect(api_opts)...)
Expand Down
Loading

0 comments on commit eed9ea7

Please sign in to comment.