Error: Git requires both a URL and a ref to clone | |||||
################################################# | |||||
This error occurs when attempting to add an entry to the package catalog that | |||||
uses the ``Git`` acquisition method. | |||||
When ``dds`` obtains a package from the catalog using the ``Git`` method, it | |||||
needs a URL to clone from, and a Git ref to clone. ``dds`` uses a technique | |||||
known as "shallow cloning," which requires a known Git reference to clone from | |||||
the reference may be a tag, branch, or an individual commit (Using a Git commit | |||||
as the ``ref`` requires support from the remote Git server, and it is often | |||||
unavailable in most setups). Using a Git tag is strongly recommended. | |||||
.. seealso:: | |||||
Refer to the documentation on :doc:`/guide/catalog`. |
if (git_url) { | if (git_url) { | ||||
if (!git_ref) { | if (!git_ref) { | ||||
throw std::runtime_error( | |||||
"`--git-ref` must be specified when using `--git-url`"); | |||||
dds::throw_user_error<dds::errc::git_url_ref_mutual_req>(); | |||||
} | } | ||||
auto git = dds::git_remote_listing{git_url.Get(), git_ref.Get(), std::nullopt}; | auto git = dds::git_remote_listing{git_url.Get(), git_ref.Get(), std::nullopt}; | ||||
if (auto_lib) { | if (auto_lib) { | ||||
git.auto_lib = lm::split_usage_string(auto_lib.Get()); | git.auto_lib = lm::split_usage_string(auto_lib.Get()); | ||||
} | } | ||||
info.remote = std::move(git); | info.remote = std::move(git); | ||||
} else if (git_ref) { | |||||
dds::throw_user_error<dds::errc::git_url_ref_mutual_req>(); | |||||
} | } | ||||
cat_path.open().store(info); | cat_path.open().store(info); |
return "invalid-builtin-toolchain.html"; | return "invalid-builtin-toolchain.html"; | ||||
case errc::no_such_catalog_package: | case errc::no_such_catalog_package: | ||||
return "no-such-catalog-package.html"; | return "no-such-catalog-package.html"; | ||||
case errc::git_url_ref_mutual_req: | |||||
return "git-url-ref-mutual-req.html"; | |||||
case errc::none: | case errc::none: | ||||
break; | break; | ||||
} | } | ||||
return R"( | return R"( | ||||
The installation of a package was requested, but the given package ID was not | The installation of a package was requested, but the given package ID was not | ||||
able to be found in the package catalog. Check the spelling and version number. | able to be found in the package catalog. Check the spelling and version number. | ||||
)"; | |||||
case errc::git_url_ref_mutual_req: | |||||
return R"( | |||||
Creating a Git-based catalog entry requires both a URL to clone from and a Git | |||||
reference (tag, branch, commit) to clone. | |||||
)"; | )"; | ||||
case errc::none: | case errc::none: | ||||
break; | break; | ||||
assert(false && "Unexpected execution path during error explanation. This is a DDS bug"); | assert(false && "Unexpected execution path during error explanation. This is a DDS bug"); | ||||
std::terminate(); | std::terminate(); | ||||
} | } | ||||
std::string_view dds::default_error_string(dds::errc ec) noexcept { | |||||
switch (ec) { | |||||
case errc::invalid_builtin_toolchain: | |||||
return "The built-in toolchain name is invalid"; | |||||
case errc::no_such_catalog_package: | |||||
return "The catalog has no entry for the given package ID"; | |||||
case errc::git_url_ref_mutual_req: | |||||
return "Git requires both a URL and a ref to clone"; | |||||
case errc::none: | |||||
break; | |||||
} | |||||
assert(false && "Unexpected execution path during error message creation. This is a DDS bug"); | |||||
std::terminate(); | |||||
} |
none = 0, | none = 0, | ||||
invalid_builtin_toolchain, | invalid_builtin_toolchain, | ||||
no_such_catalog_package, | no_such_catalog_package, | ||||
git_url_ref_mutual_req, | |||||
}; | }; | ||||
std::string error_reference_of(errc) noexcept; | std::string error_reference_of(errc) noexcept; | ||||
std::string_view explanation_of(errc) noexcept; | std::string_view explanation_of(errc) noexcept; | ||||
std::string_view default_error_string(errc) noexcept; | |||||
template <errc ErrorCode> | template <errc ErrorCode> | ||||
struct user_error : user_error_base { | struct user_error : user_error_base { | ||||
throw user_error<ErrorCode>(fmt::format(fmt_str, std::forward<Args>(args)...)); | throw user_error<ErrorCode>(fmt::format(fmt_str, std::forward<Args>(args)...)); | ||||
} | } | ||||
template <errc ErrorCode> | |||||
[[noreturn]] void throw_user_error() { | |||||
throw user_error<ErrorCode>(std::string(default_error_string(ErrorCode))); | |||||
} | |||||
} // namespace dds | } // namespace dds |