Skip to content

Commit 10ce826

Browse files
refactor(audience-sdk): introduce AudienceArgumentMessages catalogue
Names the ArgumentException strings thrown from public SDK surfaces so user-code that reads .Message stays in sync if a wording is tweaked in one site but not another. - Log.cs: adds AudienceArgumentMessages with the Init / config validation entries (PublishableKeyRequired, PersistentDataPathRequired) and the typed-event ToProperties entries (ProgressionStatusRequired, ResourceFlow / Currency / AmountRequired, PurchaseValue / CurrencyInvalid, MilestoneReachedNameRequired). - TypedEvents.cs: Progression / Resource / Purchase / MilestoneReached ArgumentException messages route through AudienceArgumentMessages. - ImmutableAudience.cs: Init validation ArgumentException messages route through AudienceArgumentMessages.
1 parent 16f0389 commit 10ce826

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

src/Packages/Audience/Runtime/Events/TypedEvents.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class Progression : IEvent
8484
public Dictionary<string, object> ToProperties()
8585
{
8686
if (Status is null)
87-
throw new ArgumentException("Progression.Status is required. Set it before calling Track(IEvent).");
87+
throw new ArgumentException(AudienceArgumentMessages.ProgressionStatusRequired);
8888

8989
var props = new Dictionary<string, object>
9090
{
@@ -169,11 +169,11 @@ public class Resource : IEvent
169169
public Dictionary<string, object> ToProperties()
170170
{
171171
if (Flow is null)
172-
throw new ArgumentException("Resource.Flow is required. Set it before calling Track(IEvent).");
172+
throw new ArgumentException(AudienceArgumentMessages.ResourceFlowRequired);
173173
if (string.IsNullOrEmpty(Currency))
174-
throw new ArgumentException("Resource.Currency is required. Set a non-empty string before calling Track(IEvent).");
174+
throw new ArgumentException(AudienceArgumentMessages.ResourceCurrencyRequired);
175175
if (Amount is null)
176-
throw new ArgumentException("Resource.Amount is required. Set it before calling Track(IEvent).");
176+
throw new ArgumentException(AudienceArgumentMessages.ResourceAmountRequired);
177177

178178
var props = new Dictionary<string, object>
179179
{
@@ -245,10 +245,9 @@ private static bool IsIso4217(string s)
245245
public Dictionary<string, object> ToProperties()
246246
{
247247
if (Currency == null || !IsIso4217(Currency))
248-
throw new ArgumentException(
249-
$"Purchase.Currency '{Currency}' must be a three-letter uppercase ISO 4217 code");
248+
throw new ArgumentException(AudienceArgumentMessages.PurchaseCurrencyInvalid(Currency));
250249
if (Value is null)
251-
throw new ArgumentException("Purchase.Value is required. Set it before calling Track(IEvent).");
250+
throw new ArgumentException(AudienceArgumentMessages.PurchaseValueRequired);
252251

253252
var props = new Dictionary<string, object>
254253
{
@@ -284,7 +283,7 @@ public class MilestoneReached : IEvent
284283
public Dictionary<string, object> ToProperties()
285284
{
286285
if (string.IsNullOrEmpty(Name))
287-
throw new ArgumentException("MilestoneReached.Name must not be null or empty");
286+
throw new ArgumentException(AudienceArgumentMessages.MilestoneReachedNameRequired);
288287

289288
return new Dictionary<string, object>
290289
{

src/Packages/Audience/Runtime/ImmutableAudience.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ public static void Init(AudienceConfig config)
146146
{
147147
if (config == null) throw new ArgumentNullException(nameof(config));
148148
if (string.IsNullOrEmpty(config.PublishableKey))
149-
throw new ArgumentException("PublishableKey is required", nameof(config));
149+
throw new ArgumentException(AudienceArgumentMessages.PublishableKeyRequired, nameof(config));
150150

151151
if (string.IsNullOrEmpty(config.PersistentDataPath))
152152
config.PersistentDataPath = DefaultPersistentDataPathProvider?.Invoke();
153153
if (string.IsNullOrEmpty(config.PersistentDataPath))
154-
throw new ArgumentException("PersistentDataPath is required", nameof(config));
154+
throw new ArgumentException(AudienceArgumentMessages.PersistentDataPathRequired, nameof(config));
155155

156156
// Normalize casing so dashboards aggregate consistently. The
157157
// DistributionPlatforms constants ship lowercase; a studio that

src/Packages/Audience/Runtime/Utility/Log.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ private static void Emit(string line)
4343
}
4444
}
4545

46+
// ArgumentException messages thrown from public SDK methods.
47+
internal static class AudienceArgumentMessages
48+
{
49+
// Init / config validation
50+
internal const string PublishableKeyRequired = "PublishableKey is required";
51+
internal const string PersistentDataPathRequired = "PersistentDataPath is required";
52+
53+
// Typed-event ToProperties validation
54+
internal const string ProgressionStatusRequired = "Progression.Status is required. Set it before calling Track(IEvent).";
55+
internal const string ResourceFlowRequired = "Resource.Flow is required. Set it before calling Track(IEvent).";
56+
internal const string ResourceCurrencyRequired = "Resource.Currency is required. Set a non-empty string before calling Track(IEvent).";
57+
internal const string ResourceAmountRequired = "Resource.Amount is required. Set it before calling Track(IEvent).";
58+
internal const string PurchaseValueRequired = "Purchase.Value is required. Set it before calling Track(IEvent).";
59+
internal const string MilestoneReachedNameRequired = "MilestoneReached.Name must not be null or empty";
60+
61+
internal static string PurchaseCurrencyInvalid(string? currency) =>
62+
$"Purchase.Currency '{currency}' must be a three-letter uppercase ISO 4217 code";
63+
}
64+
4665
// Error messages we pass to AudienceConfig.OnError.
4766
internal static class AudienceErrorMessages
4867
{

0 commit comments

Comments
 (0)