Skip to content

Commit 8ad9144

Browse files
authored
Merge pull request #69840 from dibarbet/log_uri_failures
Include URI string when we get an exception creating a URI
2 parents 9aea0f4 + f35e76f commit 8ad9144

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Features/LanguageServer/Protocol/Extensions/ProtocolConversions.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,23 @@ public static string GetDocumentFilePathFromUri(Uri uri)
170170
/// For example, UNC paths with invalid characters in server name.
171171
/// </exception>
172172
public static Uri CreateAbsoluteUri(string absolutePath)
173+
{
174+
var uriString = IsAscii(absolutePath) ? absolutePath : GetAbsoluteUriString(absolutePath);
175+
try
176+
{
173177
#pragma warning disable RS0030 // Do not use banned APIs
174-
=> new(IsAscii(absolutePath) ? absolutePath : GetAbsoluteUriString(absolutePath), UriKind.Absolute);
178+
return new(uriString, UriKind.Absolute);
175179
#pragma warning restore
176180

181+
}
182+
catch (UriFormatException e)
183+
{
184+
// The standard URI format exception does not include the failing path, however
185+
// in pretty much all cases we need to know the URI string (and original string) in order to fix the issue.
186+
throw new UriFormatException($"Failed create URI from '{uriString}'; original string: '{absolutePath}'", e);
187+
}
188+
}
189+
177190
// Implements workaround for https://github.com/dotnet/runtime/issues/89538:
178191
internal static string GetAbsoluteUriString(string absolutePath)
179192
{

0 commit comments

Comments
 (0)