Fix NRE when Tags is null and error if both tags and connection string are specified (#9)

This commit is contained in:
Gervasio Marchand 2022-12-20 16:34:43 -08:00 committed by GitHub
parent a88e9f9fd5
commit 518b51fcf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -50,6 +50,12 @@ public class Config
Console.WriteLine("Warning: Sites is deprecated, please use Instances instead");
}
data.Tags ??= Array.Empty<string>();
if (data.MastodonPostgresConnectionString.HasValue() && data.Tags.Length > 0)
{
throw new Exception("You can't specify both MastodonPostgresConnectionString and Tags");
}
Instance = new Config(importedPath, data.FakeRelayUrl, apiKey, data.MastodonPostgresConnectionString,
data.Tags.ToImmutableArray(), data.GetImmutableSites());
}
@ -60,7 +66,7 @@ public class Config
public string? FakeRelayApiKey { get; set; }
public string? MastodonPostgresConnectionString { get; set; }
public string[]? Instances { get; set; }
public string[] Tags { get; set; }
public string[]? Tags { get; set; }
public InternalSiteData[]? Sites { get; set; }
public ImmutableArray<SiteData> GetImmutableSites()

8
src/Extensions.cs Normal file
View File

@ -0,0 +1,8 @@
namespace GetMoarFediverse;
public static class Extensions
{
public static bool IsNullOrEmpty(this string s) => string.IsNullOrEmpty(s);
public static bool HasValue(this string s) => !s.IsNullOrEmpty();
}