Skip to content

Commit

Permalink
#3008 Don't append location/position information to the error message…
Browse files Browse the repository at this point in the history
… if none is present
  • Loading branch information
brianpos committed Jan 14, 2025
1 parent c32024b commit fa4bd61
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Hl7.Fhir.Base/Utility/ExtendedCodedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ public ExtendedCodedException(

private static string formatLocationMessage(string baseMessage, string? instancePath, long? lineNumber, long? position)
{
string location = $"At line {lineNumber}, position {position}";
// If there is no location data, just return the base message
if (string.IsNullOrEmpty(instancePath) && !lineNumber.HasValue && !position.HasValue)
return baseMessage;

string? location = null;
if (!string.IsNullOrEmpty(instancePath))
location = $"At {instancePath}, line {lineNumber}, position {position}";
var messageWithLocation = $"{baseMessage} {location}";
location += instancePath;
if (lineNumber.HasValue && position.HasValue)
{
if (!string.IsNullOrEmpty(location))
location += ", ";
location += $"line {lineNumber}, position {position}";
}
var messageWithLocation = $"{baseMessage} At {location}";
return messageWithLocation;
}

Expand Down

0 comments on commit fa4bd61

Please sign in to comment.