Skip to content

Commit 80b9da7

Browse files
authored
Add exception handling to C# generator to help identify which definitions are having problems (#758)
When the telemetry definitions contain a general error, it can be hard to tell where the problem is when looking at the C# generator output. ## Solution Add exception handling that indicates which entity was being processed.
1 parent 426aca7 commit 80b9da7

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

telemetry/csharp/AwsToolkit.Telemetry.Events.Generator/DefinitionsBuilder.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,18 @@ private void ProcessMetricTypes(CodeNamespace generatedNamespace)
163163
/// </summary>
164164
internal void ProcessMetricType(MetricType type, CodeNamespace generatedNamespace)
165165
{
166-
// Handle non-POCO types
167-
if (!type.IsAliasedType())
166+
try
168167
{
169-
// Generate strongly typed code for types that contain "allowed values"
170-
generatedNamespace.Types.Add(GenerateEnumStruct(type));
168+
// Handle non-POCO types
169+
if (!type.IsAliasedType())
170+
{
171+
// Generate strongly typed code for types that contain "allowed values"
172+
generatedNamespace.Types.Add(GenerateEnumStruct(type));
173+
}
174+
}
175+
catch (Exception ex)
176+
{
177+
throw new Exception($"Failed to generate code for metric type: {type.name}", ex);
171178
}
172179
}
173180

@@ -253,8 +260,15 @@ private void ProcessMetrics(CodeTypeDeclaration telemetryEventsClass, CodeNamesp
253260
/// </summary>
254261
private void ProcessMetric(Metric metric, CodeTypeDeclaration telemetryEventsClass, CodeNamespace generatedNamespace)
255262
{
256-
generatedNamespace.Types.Add(CreateMetricDataClass(metric));
257-
telemetryEventsClass.Members.Add(CreateRecordMetricMethodByDataClass(metric));
263+
try
264+
{
265+
generatedNamespace.Types.Add(CreateMetricDataClass(metric));
266+
telemetryEventsClass.Members.Add(CreateRecordMetricMethodByDataClass(metric));
267+
}
268+
catch (Exception ex)
269+
{
270+
throw new Exception($"Failed to generate code for metric: {metric.name}", ex);
271+
}
258272
}
259273

260274
/// <summary>
@@ -542,7 +556,14 @@ private bool IsNullable(Metadata metadata)
542556

543557
private MetricType GetMetricType(string name)
544558
{
545-
return _types.Single(t => t.name == name);
559+
try
560+
{
561+
return _types.Single(t => t.name == name);
562+
}
563+
catch (Exception e)
564+
{
565+
throw new Exception($"Unable to find metric type: {name}", e);
566+
}
546567
}
547568

548569
private string SanitizeName(string name)

0 commit comments

Comments
 (0)