Skip to content

Commit 34f1eb4

Browse files
committed
Don't cache failed parsing attempts
1 parent 45ef0bd commit 34f1eb4

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

src/Elastic.Documentation/AppliesTo/ApplicableToParser.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,20 @@ public static class ApplicableToParser
2929
/// <returns>The parsed ApplicableTo object, or null if parsing failed</returns>
3030
public static ApplicableTo? ParseApplicableTo(string yaml)
3131
{
32-
// Check cache first
3332
if (ParsedCache.TryGetValue(yaml, out var cached))
3433
return cached;
3534

36-
// Parse and cache the result
3735
ApplicableTo? parsed = null;
3836
try
3937
{
4038
parsed = Deserializer.Deserialize<ApplicableTo>(yaml);
39+
_ = ParsedCache.TryAdd(yaml, parsed);
4140
}
42-
catch
41+
catch (Exception ex)
4342
{
44-
// If parsing fails, cache null to avoid retrying
43+
System.Diagnostics.Debug.WriteLine($"Failed to parse ApplicableTo YAML: {yaml}. Error: {ex.Message}");
4544
}
4645

47-
// Cache the result (including null for failed parses)
48-
_ = ParsedCache.TryAdd(yaml, parsed);
4946
return parsed;
5047
}
5148

src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268,22 +268,7 @@ private static void WriteAppliesSwitch(HtmlRenderer renderer, AppliesSwitchBlock
268268
private static void WriteAppliesItem(HtmlRenderer renderer, AppliesItemBlock block)
269269
{
270270
// Parse the applies_to definition to get the ApplicableTo object
271-
ApplicableTo? appliesTo = null;
272-
try
273-
{
274-
appliesTo = ApplicableToParser.ParseApplicableTo(block.AppliesToDefinition);
275-
if (appliesTo?.Diagnostics is not null)
276-
{
277-
foreach (var (severity, message) in appliesTo.Diagnostics)
278-
block.Emit(severity, message);
279-
appliesTo.Diagnostics = null;
280-
}
281-
}
282-
catch (Exception e)
283-
{
284-
block.EmitError($"Unable to parse applies_to definition: {block.AppliesToDefinition}", e);
285-
}
286-
271+
var appliesTo = ApplicableToParser.ParseApplicableTo(block.AppliesToDefinition);
287272
var slice = AppliesItemView.Create(new AppliesItemViewModel
288273
{
289274
DirectiveBlock = block,

0 commit comments

Comments
 (0)