aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-22 17:58:59 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:32 +0200
commit48483eab86f52a1eac64b56e767e88b86f665988 (patch)
tree76707d53c5ef2e5abde27059b668c60a82d07b9e /src
parent0d0fa21e695f3082576053bf0c9b71a3bcc154a4 (diff)
Fix crash on windows when dependency is not found
Diffstat (limited to 'src')
-rw-r--r--src/Package.cpp42
1 files changed, 25 insertions, 17 deletions
diff --git a/src/Package.cpp b/src/Package.cpp
index d59c6a9..5969ac5 100644
--- a/src/Package.cpp
+++ b/src/Package.cpp
@@ -27,20 +27,20 @@ namespace sibs
Result<PackageMetadata> getPackageMetadata(Value::ConstObject jsonObj)
{
- const auto &description = jsonObj["description"];
- if(!description.IsString()) return Result<PackageMetadata>::Err("Expected description to be a string");
- const auto &version = jsonObj["version"];
- if(!version.IsString()) return Result<PackageMetadata>::Err("Expected version to be a string");
- const auto &platforms = jsonObj["platforms"];
- if(!platforms.IsArray() || platforms.GetArray().Empty()) return Result<PackageMetadata>::Err("Expected platforms to be an array of strings");
- const auto &urls = jsonObj["urls"];
- if(!urls.IsArray() || urls.GetArray().Empty()) return Result<PackageMetadata>::Err("Expected urls to be an array of string");
+ const auto &description = jsonObj.FindMember("description");
+ if(description == jsonObj.MemberEnd() || !description->value.IsString()) return Result<PackageMetadata>::Err("Expected description to be a string");
+ const auto &version = jsonObj.FindMember("version");
+ if(version == jsonObj.MemberEnd() || !version->value.IsString()) return Result<PackageMetadata>::Err("Expected version to be a string");
+ const auto &platforms = jsonObj.FindMember("platforms");
+ if(platforms == jsonObj.MemberEnd() || !platforms->value.IsArray() || platforms->value.GetArray().Empty()) return Result<PackageMetadata>::Err("Expected platforms to be an array of strings");
+ const auto &urls = jsonObj.FindMember("urls");
+ if(urls == jsonObj.MemberEnd() || !urls->value.IsArray() || urls->value.GetArray().Empty()) return Result<PackageMetadata>::Err("Expected urls to be an array of string");
PackageMetadata packageMetadata;
- packageMetadata.description.assign(description.GetString(), description.GetStringLength());
- packageMetadata.version.assign(version.GetString(), version.GetStringLength());
+ packageMetadata.description.assign(description->value.GetString(), description->value.GetStringLength());
+ packageMetadata.version.assign(version->value.GetString(), version->value.GetStringLength());
- const auto &platformsArray = platforms.GetArray();
+ const auto &platformsArray = platforms->value.GetArray();
packageMetadata.platforms.reserve(platformsArray.Size());
for(int i = 0; i < platformsArray.Size(); ++i)
{
@@ -50,7 +50,7 @@ namespace sibs
packageMetadata.platforms.push_back(platformElement.GetString());
}
- const auto &urlsArray = urls.GetArray();
+ const auto &urlsArray = urls->value.GetArray();
packageMetadata.urls.reserve(urlsArray.Size());
for(int i = 0; i < urlsArray.Size(); ++i)
{
@@ -129,17 +129,25 @@ namespace sibs
const Document &packageDoc = *packageList.unwrap();
- const Value &packageMetaDataJson = packageDoc[packageName];
- if(packageMetaDataJson.IsObject())
+ auto packageMetaDataJsonIt = packageDoc.FindMember(packageName);
+ if (packageMetaDataJsonIt == packageDoc.MemberEnd())
+ {
+ string errMsg = "No package with the name \"";
+ errMsg += packageName;
+ errMsg += "\" was found";
+ return Result<string>::Err(errMsg);
+ }
+
+ if(packageMetaDataJsonIt->value.IsObject())
{
- Result<PackageMetadata> packageMetadataResult = getPackageMetadata(packageMetaDataJson.GetObject());
+ Result<PackageMetadata> packageMetadataResult = getPackageMetadata(packageMetaDataJsonIt->value.GetObject());
if(!packageMetadataResult) return Result<string>::Err(packageMetadataResult);
return ::sibs::getPackageUrl(packageMetadataResult.unwrap(), packageName, packageVersion, platform);
}
- else if(packageMetaDataJson.IsArray())
+ else if(packageMetaDataJsonIt->value.IsArray())
{
int i = 0;
- for(const auto &packageData : packageMetaDataJson.GetArray())
+ for(const auto &packageData : packageMetaDataJsonIt->value.GetArray())
{
if(!packageData.IsObject())
{