From eed9ea7fb6c927432954987ac46d89791f0804b3 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Sat, 4 Aug 2018 01:15:19 +0200 Subject: [PATCH] rename CommandError to PkgError (#475) --- stdlib/Pkg/src/API.jl | 18 ++--- stdlib/Pkg/src/GitTools.jl | 8 +-- stdlib/Pkg/src/Operations.jl | 22 +++---- stdlib/Pkg/src/Pkg.jl | 2 +- stdlib/Pkg/src/REPLMode.jl | 44 ++++++------- stdlib/Pkg/src/Types.jl | 32 ++++----- stdlib/Pkg/src/generate.jl | 2 +- stdlib/Pkg/test/pkg.jl | 16 ++--- stdlib/Pkg/test/repl.jl | 123 ++++++++++++++++++----------------- stdlib/Pkg/test/resolve.jl | 2 +- 10 files changed, 136 insertions(+), 133 deletions(-) diff --git a/stdlib/Pkg/src/API.jl b/stdlib/Pkg/src/API.jl index a57b39edd35a8..09d807b0e0a74 100644 --- a/stdlib/Pkg/src/API.jl +++ b/stdlib/Pkg/src/API.jl @@ -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 @@ -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 @@ -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() @@ -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 @@ -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) @@ -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) @@ -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} @@ -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{} @@ -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) diff --git a/stdlib/Pkg/src/GitTools.jl b/stdlib/Pkg/src/GitTools.jl index 05d4dc6998318..acd988ead9bd9 100644 --- a/stdlib/Pkg/src/GitTools.jl +++ b/stdlib/Pkg/src/GitTools.jl @@ -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 @@ -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 diff --git a/stdlib/Pkg/src/Operations.jl b/stdlib/Pkg/src/Operations.jl index d809d584bc72a..468c48a941a9b 100644 --- a/stdlib/Pkg/src/Operations.jl +++ b/stdlib/Pkg/src/Operations.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -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"] @@ -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 @@ -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]" @@ -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 @@ -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") @@ -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 @@ -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 diff --git a/stdlib/Pkg/src/Pkg.jl b/stdlib/Pkg/src/Pkg.jl index 1f0b83db24a78..e1551c0e0369e 100644 --- a/stdlib/Pkg/src/Pkg.jl +++ b/stdlib/Pkg/src/Pkg.jl @@ -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 diff --git a/stdlib/Pkg/src/REPLMode.jl b/stdlib/Pkg/src/REPLMode.jl index 29dd6a44e774e..39366bc5a207c 100644 --- a/stdlib/Pkg/src/REPLMode.jl +++ b/stdlib/Pkg/src/REPLMode.jl @@ -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) @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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()) @@ -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 @@ -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) @@ -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)...) diff --git a/stdlib/Pkg/src/Types.jl b/stdlib/Pkg/src/Types.jl index 68d2cac2c9a36..b867186ef89ad 100644 --- a/stdlib/Pkg/src/Types.jl +++ b/stdlib/Pkg/src/Types.jl @@ -19,7 +19,7 @@ using SHA export UUID, pkgID, SHA1, VersionRange, VersionSpec, empty_versionspec, Requires, Fixed, merge_requires!, satisfies, ResolverError, PackageSpec, EnvCache, Context, Context!, - CommandError, cmderror, has_name, has_uuid, write_env, parse_toml, find_registered!, + PkgError, pkgerror, has_name, has_uuid, write_env, parse_toml, find_registered!, project_resolve!, project_deps_resolve!, manifest_resolve!, registry_resolve!, stdlib_resolve!, handle_repos_develop!, handle_repos_add!, ensure_resolved, manifest_info, registered_uuids, registered_paths, registered_uuid, registered_name, read_project, read_package, read_manifest, pathrepr, registries, @@ -112,13 +112,13 @@ function Base.showerror(io::IO, pkgerr::ResolverError) end ################# -# Command Error # +# Pkg Error # ################# -struct CommandError <: Exception +struct PkgError <: Exception msg::String end -cmderror(msg::String...) = throw(CommandError(join(msg))) -Base.show(io::IO, err::CommandError) = print(io, err.msg) +pkgerror(msg::String...) = throw(PkgError(join(msg))) +Base.show(io::IO, err::PkgError) = print(io, err.msg) ############### @@ -174,7 +174,7 @@ function PackageSpec(;name::AbstractString="", uuid::Union{String, UUID}=UUID(0) url = nothing, rev = nothing, path=nothing, mode::PackageMode = PKGMODE_PROJECT) if url !== nothing || path !== nothing || rev !== nothing if path !== nothing || url !== nothing - path !== nothing && url !== nothing && cmderror("cannot specify both path and url") + path !== nothing && url !== nothing && pkgerror("cannot specify both path and url") url = url == nothing ? path : url end repo = GitRepo(url=url, rev=rev) @@ -398,7 +398,7 @@ function get_deps(project::Dict, target::Union{Nothing,String}=nothing) for name in names haskey(deps, name) && continue haskey(extras, name) || - cmderror("target `$target` has unlisted dependency `$name`") + pkgerror("target `$target` has unlisted dependency `$name`") deps[name] = extras[name] end return deps @@ -441,7 +441,7 @@ function read_project(file::String) isfile(file) ? open(read_project, file) : read_project(devnull) end -_throw_package_err(x, f) = cmderror("expected a `$x` entry in project file at $(abspath(f))") +_throw_package_err(x, f) = pkgerror("expected a `$x` entry in project file at $(abspath(f))") function read_package(f::String) project = read_project(f) haskey(project, "name") || _throw_package_err("name", f) @@ -449,7 +449,7 @@ function read_package(f::String) name = project["name"] entry = joinpath(dirname(f), "src", "$name.jl") if !isfile(entry) - cmderror("expected the file `src/$name.jl` to exist for package $name at $(dirname(f))") + pkgerror("expected the file `src/$name.jl` to exist for package $name at $(dirname(f))") end return project end @@ -571,7 +571,7 @@ function handle_repos_develop!(ctx::Context, pkgs::AbstractVector{PackageSpec}, dev_pkg_path = joinpath(devdir, pkg.name) if isdir(dev_pkg_path) if !isfile(joinpath(dev_pkg_path, "src", pkg.name * ".jl")) - cmderror("Path `$(dev_pkg_path)` exists but it does not contain `src/$(pkg.name).jl") + pkgerror("Path `$(dev_pkg_path)` exists but it does not contain `src/$(pkg.name).jl") else @info "Path `$(dev_pkg_path)` exists and looks like the correct package, using existing path instead of cloning" end @@ -710,7 +710,7 @@ function parse_package!(ctx, pkg, project_path) else m = match(reg_pkg, pkg.repo.url) end - m === nothing && cmderror("cannot determine package name from URL or path: $(pkg.repo.url)") + m === nothing && pkgerror("cannot determine package name from URL or path: $(pkg.repo.url)") pkg.name = m.captures[1] end reg_uuids = registered_uuids(env, pkg.name) @@ -757,7 +757,7 @@ function get_object_branch(repo, rev) gitobject = LibGit2.GitObject(repo, rev) catch err err isa LibGit2.GitError && err.code == LibGit2.Error.ENOTFOUND || rethrow(err) - cmderror("git object $(rev) could not be found") + pkgerror("git object $(rev) could not be found") end end return gitobject, isbranch @@ -783,7 +783,7 @@ function project_deps_resolve!(env::EnvCache, pkgs::AbstractVector{PackageSpec}) uuids = env.project["deps"] names = Dict(uuid => name for (uuid, name) in uuids) length(uuids) < length(names) && # TODO: handle this somehow? - cmderror("duplicate UUID found in project file's [deps] section") + pkgerror("duplicate UUID found in project file's [deps] section") for pkg in pkgs pkg.mode == PKGMODE_PROJECT || continue if has_name(pkg) && !has_uuid(pkg) && pkg.name in keys(uuids) @@ -886,7 +886,7 @@ function ensure_resolved(env::EnvCache, end print(io, "Please specify by known `name=uuid`.") end - cmderror(msg) + pkgerror(msg) end const DEFAULT_REGISTRIES = Dict("General" => "https://github.com/JuliaRegistries/General.git") @@ -1066,7 +1066,7 @@ function registered_name(env::EnvCache, uuid::UUID)::String name = nothing for value in values name == nothing && (name = value[2]) - name != value[2] && cmderror("package `$uuid` has multiple registered name values: $name, $(value[2])") + name != value[2] && pkgerror("package `$uuid` has multiple registered name values: $name, $(value[2])") end return name end @@ -1074,7 +1074,7 @@ end # Return most current package info for a registered UUID function registered_info(env::EnvCache, uuid::UUID, key::String) paths = env.paths[uuid] - isempty(paths) && cmderror("`$uuid` is not registered") + isempty(paths) && pkgerror("`$uuid` is not registered") values = [] for path in paths info = parse_toml(path, "Package.toml") diff --git a/stdlib/Pkg/src/generate.jl b/stdlib/Pkg/src/generate.jl index 04663c7196ae8..bd5d57cc93605 100644 --- a/stdlib/Pkg/src/generate.jl +++ b/stdlib/Pkg/src/generate.jl @@ -5,7 +5,7 @@ function generate(ctx::Context, path::String; kwargs...) Context!(ctx; kwargs...) ctx.preview && preview_info() dir, pkg = dirname(path), basename(path) - isdir(path) && cmderror("$(abspath(path)) already exists") + isdir(path) && pkgerror("$(abspath(path)) already exists") printstyled("Generating"; color=:green, bold=true) print(" project $pkg:\n") project(pkg, dir; preview=ctx.preview) diff --git a/stdlib/Pkg/test/pkg.jl b/stdlib/Pkg/test/pkg.jl index 3fb935e1efd0f..92aac84606b37 100644 --- a/stdlib/Pkg/test/pkg.jl +++ b/stdlib/Pkg/test/pkg.jl @@ -215,7 +215,7 @@ temp_pkg_dir() do project_path end @testset "invalid pkg name" begin - @test_throws CommandError Pkg.add(",sa..,--") + @test_throws PkgError Pkg.add(",sa..,--") end @testset "stdlibs as direct dependency" begin @@ -241,7 +241,7 @@ temp_pkg_dir() do project_path withenv("JULIA_PKG_DEVDIR" => devdir) do try Pkg.setprotocol!("notarealprotocol") - @test_throws CommandError Pkg.develop("Example") + @test_throws PkgError Pkg.develop("Example") Pkg.setprotocol!("https") Pkg.develop("Example") @test isinstalled(TEST_PKG) @@ -259,8 +259,8 @@ temp_pkg_dir() do project_path @testset "adding nonexisting packages" begin nonexisting_pkg = randstring(14) - @test_throws CommandError Pkg.add(nonexisting_pkg) - @test_throws CommandError Pkg.update(nonexisting_pkg) + @test_throws PkgError Pkg.add(nonexisting_pkg) + @test_throws PkgError Pkg.update(nonexisting_pkg) end Pkg.rm(TEST_PKG.name) @@ -281,7 +281,7 @@ temp_pkg_dir() do project_path end @testset "add julia" begin - @test_throws CommandError Pkg.add("julia") + @test_throws PkgError Pkg.add("julia") end end @@ -390,9 +390,9 @@ end temp_pkg_dir() do project_path @testset "invalid repo url" begin cd(project_path) do - @test_throws CommandError Pkg.add("https://github.com") + @test_throws PkgError Pkg.add("https://github.com") Pkg.generate("FooBar") - @test_throws CommandError Pkg.add("./Foobar") + @test_throws PkgError Pkg.add("./Foobar") end end end @@ -408,7 +408,7 @@ temp_pkg_dir() do project_path Pkg.add(PackageSpec(path=package_path)) end rm(joinpath(package_path, ".git"); force=true, recursive=true) - @test_throws CommandError Pkg.update() + @test_throws PkgError Pkg.update() end end end diff --git a/stdlib/Pkg/test/repl.jl b/stdlib/Pkg/test/repl.jl index 374815d0044fb..c29c5ff165a84 100644 --- a/stdlib/Pkg/test/repl.jl +++ b/stdlib/Pkg/test/repl.jl @@ -3,7 +3,7 @@ module REPLTests using Pkg -import Pkg.Types.CommandError +import Pkg.Types.PkgError using UUIDs using Test import LibGit2 @@ -25,7 +25,7 @@ function git_init_package(tmp, path) end @testset "generate args" begin - @test_throws CommandError pkg"generate" + @test_throws PkgError pkg"generate" end temp_pkg_dir() do project_path @@ -56,18 +56,18 @@ temp_pkg_dir() do project_path pkg"generate Foo" pkg"dev Foo" mv(joinpath("Foo", "src", "Foo.jl"), joinpath("Foo", "src", "Foo2.jl")) - @test_throws CommandError pkg"dev Foo" + @test_throws PkgError pkg"dev Foo" mv(joinpath("Foo", "src", "Foo2.jl"), joinpath("Foo", "src", "Foo.jl")) write(joinpath("Foo", "Project.toml"), """ name = "Foo" """ ) - @test_throws CommandError pkg"dev Foo" + @test_throws PkgError pkg"dev Foo" write(joinpath("Foo", "Project.toml"), """ uuid = "b7b78b08-812d-11e8-33cd-11188e330cbe" """ ) - @test_throws CommandError pkg"dev Foo" + @test_throws PkgError pkg"dev Foo" end end @@ -135,7 +135,7 @@ temp_pkg_dir() do project_path; cd(project_path) do; mktempdir() do tmp_pkg_path #@eval import $(Symbol(pkg2)) @test Pkg.installed()[pkg2] == v"0.1.0" Pkg.REPLMode.pkgstr("free $pkg2") - @test_throws CommandError Pkg.REPLMode.pkgstr("free $pkg2") + @test_throws PkgError Pkg.REPLMode.pkgstr("free $pkg2") Pkg.test("UnregisteredWithProject") write(joinpath(p2, "Project.toml"), """ @@ -263,10 +263,10 @@ temp_pkg_dir() do project_path pkg"activate ." @test Base.active_project() == joinpath(path, "Project.toml") # tests illegal names for shared environments - @test_throws Pkg.Types.CommandError pkg"activate --shared ." - @test_throws Pkg.Types.CommandError pkg"activate --shared ./Foo" - @test_throws Pkg.Types.CommandError pkg"activate --shared Foo/Bar" - @test_throws Pkg.Types.CommandError pkg"activate --shared ../Bar" + @test_throws Pkg.Types.PkgError pkg"activate --shared ." + @test_throws Pkg.Types.PkgError pkg"activate --shared ./Foo" + @test_throws Pkg.Types.PkgError pkg"activate --shared Foo/Bar" + @test_throws Pkg.Types.PkgError pkg"activate --shared ../Bar" # check that those didn't change te enviroment @test Base.active_project() == joinpath(path, "Project.toml") mkdir("Foo") @@ -420,11 +420,14 @@ temp_pkg_dir() do project_path; cd(project_path) do pkg"build" @eval using BigProject pkg"build BigProject" - @test_throws CommandError pkg"add BigProject" - pkg"test SubModule" - pkg"test SubModule2" - pkg"test BigProject" - pkg"test" + @test_throws PkgError pkg"add BigProject" + # the command below also tests multiline input + Pkg.REPLMode.pkgstr(""" + test SubModule + test SubModule2 + test BigProject + test + """) current_json = Pkg.API.installed()["JSON"] old_project = read("Project.toml", String) open("Project.toml"; append=true) do io @@ -541,8 +544,8 @@ end pkg = Pkg.REPLMode.parse_package(path; add_or_develop=true) @test (pkg.repo.url == path) # errors - @test_throws CommandError Pkg.REPLMode.parse_package(url) - @test_throws CommandError Pkg.REPLMode.parse_package(path) + @test_throws PkgError Pkg.REPLMode.parse_package(url) + @test_throws PkgError Pkg.REPLMode.parse_package(path) end @testset "unit test for REPLMode.promptf" begin @@ -583,18 +586,18 @@ end @testset "Argument order" begin with_temp_env() do - @test_throws CommandError Pkg.REPLMode.pkgstr("add FooBar Example#foobar#foobar") - @test_throws CommandError Pkg.REPLMode.pkgstr("up Example#foobar@0.0.0") - @test_throws CommandError Pkg.REPLMode.pkgstr("pin Example@0.0.0@0.0.1") - @test_throws CommandError Pkg.REPLMode.pkgstr("up #foobar") - @test_throws CommandError Pkg.REPLMode.pkgstr("add @0.0.1") + @test_throws PkgError Pkg.REPLMode.pkgstr("add FooBar Example#foobar#foobar") + @test_throws PkgError Pkg.REPLMode.pkgstr("up Example#foobar@0.0.0") + @test_throws PkgError Pkg.REPLMode.pkgstr("pin Example@0.0.0@0.0.1") + @test_throws PkgError Pkg.REPLMode.pkgstr("up #foobar") + @test_throws PkgError Pkg.REPLMode.pkgstr("add @0.0.1") end end @testset "`do_generate!` error paths" begin with_temp_env() do - @test_throws CommandError Pkg.REPLMode.pkgstr("generate Example Example2") - @test_throws CommandError Pkg.REPLMode.pkgstr("generate") + @test_throws PkgError Pkg.REPLMode.pkgstr("generate Example Example2") + @test_throws PkgError Pkg.REPLMode.pkgstr("generate") end end @@ -670,9 +673,9 @@ end @testset "argument count errors" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; - @test_throws CommandError Pkg.REPLMode.pkgstr("activate one two") - @test_throws CommandError Pkg.REPLMode.pkgstr("activate one two three") - @test_throws CommandError Pkg.REPLMode.pkgstr("precompile Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("activate one two") + @test_throws PkgError Pkg.REPLMode.pkgstr("activate one two three") + @test_throws PkgError Pkg.REPLMode.pkgstr("precompile Example") end end end @@ -680,8 +683,8 @@ end @testset "invalid options" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; - @test_throws CommandError Pkg.REPLMode.pkgstr("rm --minor Example") - @test_throws CommandError Pkg.REPLMode.pkgstr("pin --project Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("rm --minor Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("pin --project Example") end end end @@ -689,11 +692,11 @@ end @testset "Argument order" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; - @test_throws CommandError Pkg.REPLMode.pkgstr("add FooBar Example#foobar#foobar") - @test_throws CommandError Pkg.REPLMode.pkgstr("up Example#foobar@0.0.0") - @test_throws CommandError Pkg.REPLMode.pkgstr("pin Example@0.0.0@0.0.1") - @test_throws CommandError Pkg.REPLMode.pkgstr("up #foobar") - @test_throws CommandError Pkg.REPLMode.pkgstr("add @0.0.1") + @test_throws PkgError Pkg.REPLMode.pkgstr("add FooBar Example#foobar#foobar") + @test_throws PkgError Pkg.REPLMode.pkgstr("up Example#foobar@0.0.0") + @test_throws PkgError Pkg.REPLMode.pkgstr("pin Example@0.0.0@0.0.1") + @test_throws PkgError Pkg.REPLMode.pkgstr("up #foobar") + @test_throws PkgError Pkg.REPLMode.pkgstr("add @0.0.1") end end end @@ -701,8 +704,8 @@ end @testset "conflicting options" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; - @test_throws CommandError Pkg.REPLMode.pkgstr("up --major --minor") - @test_throws CommandError Pkg.REPLMode.pkgstr("rm --project --manifest") + @test_throws PkgError Pkg.REPLMode.pkgstr("up --major --minor") + @test_throws PkgError Pkg.REPLMode.pkgstr("rm --project --manifest") end end end @@ -710,9 +713,9 @@ end @testset "gc" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; - @test_throws CommandError Pkg.REPLMode.pkgstr("gc --project") - @test_throws CommandError Pkg.REPLMode.pkgstr("gc --minor") - @test_throws CommandError Pkg.REPLMode.pkgstr("gc Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("gc --project") + @test_throws PkgError Pkg.REPLMode.pkgstr("gc --minor") + @test_throws PkgError Pkg.REPLMode.pkgstr("gc Example") Pkg.REPLMode.pkgstr("gc") end end @@ -721,8 +724,8 @@ end @testset "precompile" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; - @test_throws CommandError Pkg.REPLMode.pkgstr("precompile --project") - @test_throws CommandError Pkg.REPLMode.pkgstr("precompile Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("precompile --project") + @test_throws PkgError Pkg.REPLMode.pkgstr("precompile Example") Pkg.REPLMode.pkgstr("precompile") end end @@ -731,9 +734,9 @@ end @testset "generate" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; - @test_throws CommandError Pkg.REPLMode.pkgstr("generate --major Example") - @test_throws CommandError Pkg.REPLMode.pkgstr("generate --foobar Example") - @test_throws CommandError Pkg.REPLMode.pkgstr("generate Example1 Example2") + @test_throws PkgError Pkg.REPLMode.pkgstr("generate --major Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("generate --foobar Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("generate Example1 Example2") Pkg.REPLMode.pkgstr("generate Example") end end @@ -743,7 +746,7 @@ end @testset "test" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; Pkg.add("Example") - @test_throws CommandError Pkg.REPLMode.pkgstr("test --project Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("test --project Example") Pkg.REPLMode.pkgstr("test --coverage Example") Pkg.REPLMode.pkgstr("test Example") end @@ -753,8 +756,8 @@ end @testset "build" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; - @test_throws CommandError Pkg.REPLMode.pkgstr("build --project") - @test_throws CommandError Pkg.REPLMode.pkgstr("build --minor") + @test_throws PkgError Pkg.REPLMode.pkgstr("build --project") + @test_throws PkgError Pkg.REPLMode.pkgstr("build --minor") end end end @@ -762,8 +765,8 @@ end @testset "free" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; - @test_throws CommandError Pkg.REPLMode.pkgstr("free --project") - @test_throws CommandError Pkg.REPLMode.pkgstr("free --major") + @test_throws PkgError Pkg.REPLMode.pkgstr("free --project") + @test_throws PkgError Pkg.REPLMode.pkgstr("free --major") end end end @@ -784,8 +787,8 @@ end groups = Pkg.REPLMode.group_words(["a", "b", "c", ";", "a", "b", ";"]) @test length(groups) == 2 # errors - @test_throws CommandError Pkg.REPLMode.group_words(["a", "b", ";", ";", "a", "b"]) - @test_throws CommandError Pkg.REPLMode.group_words([";", "add", "Example"]) + @test_throws PkgError Pkg.REPLMode.group_words(["a", "b", ";", ";", "a", "b"]) + @test_throws PkgError Pkg.REPLMode.group_words([";", "add", "Example"]) end @testset "tests for api opts" begin @@ -825,11 +828,11 @@ end @testset "meta option errors" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; # unregistered meta options - @test_throws CommandError Pkg.REPLMode.pkgstr("--foo=foo add Example") - @test_throws CommandError Pkg.REPLMode.pkgstr("--bar add Example") - @test_throws CommandError Pkg.REPLMode.pkgstr("-x add Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("--foo=foo add Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("--bar add Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("-x add Example") # malformed, but registered meta option - @test_throws CommandError Pkg.REPLMode.pkgstr("--env Example") + @test_throws PkgError Pkg.REPLMode.pkgstr("--env Example") end end end @@ -868,15 +871,15 @@ end @test qwords[2].word == " forget to " @test qwords[3].isquoted @test qwords[3].word == "\"test\"" - @test_throws CommandError Pkg.REPLMode.parse_quotes("Don't") - @test_throws CommandError Pkg.REPLMode.parse_quotes("Unterminated \"quot") + @test_throws PkgError Pkg.REPLMode.parse_quotes("Don't") + @test_throws PkgError Pkg.REPLMode.parse_quotes("Unterminated \"quot") end @testset "argument kinds" begin temp_pkg_dir() do project_path; cd_tempdir() do tmpdir; with_temp_env() do; - @test_throws CommandError pkg"pin Example#foo" - @test_throws CommandError pkg"test Example#foo" - @test_throws CommandError pkg"test Example@v0.0.1" + @test_throws PkgError pkg"pin Example#foo" + @test_throws PkgError pkg"test Example#foo" + @test_throws PkgError pkg"test Example@v0.0.1" end end end diff --git a/stdlib/Pkg/test/resolve.jl b/stdlib/Pkg/test/resolve.jl index 20c919d8ef62e..8bfd55010b76b 100644 --- a/stdlib/Pkg/test/resolve.jl +++ b/stdlib/Pkg/test/resolve.jl @@ -54,7 +54,7 @@ function load_package_data_raw(T::Type, input::String) for (v, d) in toml, (key, value) in d vr = VersionRange(v) dict = get!(data, vr, Dict{String,T}()) - haskey(dict, key) && cmderror("$ver/$key is duplicated in $path") + haskey(dict, key) && pkgerror("$ver/$key is duplicated in $path") dict[key] = T(value) end return data