Skip to content

MetricsEventSource, unreachable logging branch #78625

@VasilievSerg

Description

@VasilievSerg

Here is the TryParse method's body:

public static bool TryParse(string text, out MetricSpec spec)
{
    int slashIdx = text.IndexOf(MeterInstrumentSeparator);
    if (slashIdx == -1)
    {
        spec = new MetricSpec(text.Trim(), null);
        return true;
    }
    else
    {
        string meterName = text.Substring(0, slashIdx).Trim();
        string? instrumentName = text.Substring(slashIdx + 1).Trim();
        spec = new MetricSpec(meterName, instrumentName);
        return true;
    }
}

It always returns true.

The ParseSpecs method uses TryParse as follows:

if (!MetricSpec.TryParse(specString, out MetricSpec spec))
{
    Log.Message($"Failed to parse metric spec: {specString}");
}
else
{
    ....
}

As a result the then branch of the if statement is unreachable.
Is the code designed for future changes in the TryParse method or is it an error here?

Links to the sources:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions