}
SecondaryStorageConfig result;
- result.params.url = std::string(parts[0]);
- // The Url class is parsing the URL object lazily; check if successful.
+ const auto url_str = std::string(parts[0]);
+ result.params.url = url_str;
+
+ // The Url class is parsing the URL object lazily. Check if the URL is valid
+ // now to avoid exceptions later.
try {
- std::ignore = result.params.url.host();
- } catch (const Url::parse_error& e) {
- throw core::Error("Cannot parse URL: {}", e.what());
+ std::ignore = result.params.url.str();
+ } catch (const std::exception& e) {
+ throw core::Error("Cannot parse URL {}: {}", url_str, e.what());
}
if (result.params.url.scheme().empty()) {
if (key == "read-only") {
result.read_only = (value == "true");
} else if (key == "shards") {
- const auto url_str = result.params.url.str();
if (url_str.find('*') == std::string::npos) {
throw core::Error(R"(Missing "*" in URL when using shards: "{}")",
url_str);
export CCACHE_SECONDARY_STORAGE="/qwerty"
$CCACHE_COMPILE -c test.c 2>stderr.log
expect_contains stderr.log "URL scheme must not be empty"
+
+ # -------------------------------------------------------------------------
+ TEST "Reject user info defined but no host"
+
+ export CCACHE_SECONDARY_STORAGE="http://foo@"
+ $CCACHE_COMPILE -c test.c 2>stderr.log
+ expect_contains stderr.log "User info defined, but host is empty"
+
+ # -------------------------------------------------------------------------
+ TEST "Reject relative path with colon in first part"
+
+ export CCACHE_SECONDARY_STORAGE="file:foo:bar"
+ $CCACHE_COMPILE -c test.c 2>stderr.log
+ expect_contains stderr.log "The first segment of the relative path can't contain ':'"
}