Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit b730eb9

Browse files
committed
Trace License exceptions so they can also be tracked with Tracer
1 parent b920d53 commit b730eb9

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/ServiceStack.Text/LicenseUtils.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static void RegisterLicense(string licenseKeyText)
7171
public static void RegisterLicenseFromFile(string filePath)
7272
{
7373
if (!filePath.FileExists())
74-
throw new LicenseException("License file does not exist: " + filePath);
74+
throw new LicenseException("License file does not exist: " + filePath).Trace();
7575

7676
var licenseKeyText = filePath.ReadAllText();
7777
LicenseUtils.RegisterLicense(licenseKeyText);
@@ -145,7 +145,7 @@ public static void AssertEvaluationLicense()
145145
{
146146
if (DateTime.UtcNow > new DateTime(2013, 12, 31))
147147
throw new LicenseException("The evaluation license for this software has expired. " +
148-
"See https://servicestack.net to upgrade to a valid license.");
148+
"See https://servicestack.net to upgrade to a valid license.").Trace();
149149
}
150150

151151
private static LicenseKey __activatedLicense;
@@ -166,7 +166,7 @@ public static void RegisterLicense(string licenseKeyText)
166166
var releaseDate = Env.GetReleaseDate();
167167
if (releaseDate > key.Expiry)
168168
throw new LicenseException("This license has expired on {0} and is not valid for use with this release."
169-
.Fmt(key.Expiry.ToString("d")) + ContactDetails);
169+
.Fmt(key.Expiry.ToString("d")) + ContactDetails).Trace();
170170

171171
__activatedLicense = key;
172172
}
@@ -179,7 +179,7 @@ public static void RegisterLicense(string licenseKeyText)
179179
if (!string.IsNullOrEmpty(cutomerId))
180180
msg += " The id for this license is '{0}'".Fmt(cutomerId);
181181

182-
throw new LicenseException(msg);
182+
throw new LicenseException(msg).Trace();
183183
}
184184
}
185185

@@ -201,7 +201,7 @@ public static void ApprovedUsage(LicenseFeature licenseFeature, LicenseFeature r
201201
return;
202202

203203
if (actualUsage > allowedUsage)
204-
throw new LicenseException(message.Fmt(allowedUsage));
204+
throw new LicenseException(message.Fmt(allowedUsage)).Trace();
205205
}
206206

207207
public static bool HasLicensedFeature(LicenseFeature feature)
@@ -283,7 +283,7 @@ public static void AssertValidUsage(LicenseFeature feature, QuotaType quotaType,
283283
break;
284284
}
285285

286-
throw new LicenseException("Unknown Quota Usage: {0}, {1}".Fmt(feature, quotaType));
286+
throw new LicenseException("Unknown Quota Usage: {0}, {1}".Fmt(feature, quotaType)).Trace();
287287
}
288288

289289
public static LicenseFeature GetLicensedFeatures(this LicenseKey key)
@@ -310,7 +310,7 @@ public static LicenseFeature GetLicensedFeatures(this LicenseKey key)
310310
case LicenseType.RedisBusiness:
311311
return LicenseFeature.RedisSku;
312312
}
313-
throw new ArgumentException("Unknown License Type: " + key.Type);
313+
throw new ArgumentException("Unknown License Type: " + key.Type).Trace();
314314
}
315315

316316
public static LicenseKey ToLicenseKey(this string licenseKeyText)
@@ -323,7 +323,7 @@ public static LicenseKey ToLicenseKey(this string licenseKeyText)
323323
var key = jsv.FromJsv<LicenseKey>();
324324

325325
if (key.Ref != refId)
326-
throw new LicenseException("The license '{0}' is not assigned to CustomerId '{1}'.".Fmt(base64));
326+
throw new LicenseException("The license '{0}' is not assigned to CustomerId '{1}'.".Fmt(base64)).Trace();
327327

328328
return key;
329329
}
@@ -385,7 +385,7 @@ public static IDisposable RequestAccess(object accessToken, LicenseFeature srcFe
385385
var accessType = accessToken.GetType();
386386

387387
if (srcFeature != LicenseFeature.Client || requestedAccess != LicenseFeature.Text || accessToken == null)
388-
throw new LicenseException(ErrorMessages.UnauthorizedAccessRequest);
388+
throw new LicenseException(ErrorMessages.UnauthorizedAccessRequest).Trace();
389389

390390
if (accessType.Name == "AccessToken" && accessType.GetAssembly().ManifestModule.Name.StartsWith("<")) //Smart Assembly
391391
return new AccessToken(requestedAccess);
@@ -396,7 +396,7 @@ public static IDisposable RequestAccess(object accessToken, LicenseFeature srcFe
396396
accessType.Name,
397397
accessType.GetAssembly().ManifestModule.Name);
398398

399-
throw new LicenseException(ErrorMessages.UnauthorizedAccessRequest + errorDetails);
399+
throw new LicenseException(ErrorMessages.UnauthorizedAccessRequest + errorDetails).Trace();
400400
}
401401

402402
PclExport.Instance.VerifyInAssembly(accessType, _approved.__dlls);

src/ServiceStack.Text/Tracer.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,13 @@ public void WriteError(string format, params object[] args)
6262
}
6363
}
6464
}
65+
66+
public static class TracerExceptions
67+
{
68+
public static T Trace<T>(this T ex) where T : Exception
69+
{
70+
Tracer.Instance.WriteError(ex);
71+
return ex;
72+
}
73+
}
6574
}

0 commit comments

Comments
 (0)