Skip to content

Localize exception messages for gladstone/roslyn integration #78063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Features/Core/Portable/Extensions/ExtensionFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void RegisterAssembly(string assemblyFilePath)
// If this throws, it also indicated a bug in gladstone that must be fixed. As such, it is ok if this
// tears down the extension service in OOP.
if (_assemblyFilePathToHandlers.ContainsKey(assemblyFilePath))
throw new InvalidOperationException($"Extension '{assemblyFilePath}' is already registered.");
throw new InvalidOperationException(string.Format(FeaturesResources.Extension_0_is_already_registered, assemblyFilePath));

_assemblyFilePathToHandlers = _assemblyFilePathToHandlers.Add(
assemblyFilePath,
Expand All @@ -141,7 +141,7 @@ public void RegisterAssembly(string assemblyFilePath)
// If this throws, it also indicated a bug in gladstone that must be fixed. As such, it is ok if this
// tears down the extension service in OOP.
if (!_assemblyFilePathToHandlers.TryGetValue(assemblyFilePath, out var lazyHandlers))
throw new InvalidOperationException($"Extension '{assemblyFilePath}' was not registered.");
throw new InvalidOperationException(string.Format(FeaturesResources.Extension_0_was_not_registered, assemblyFilePath));

_assemblyFilePathToHandlers = _assemblyFilePathToHandlers.Remove(assemblyFilePath);
return (_assemblyFilePathToHandlers.Count == 0, lazyHandlers);
Expand All @@ -156,7 +156,7 @@ public async ValueTask<ExtensionMessageNames> GetExtensionMessageNamesAsync(stri
// If this throws, it also indicated a bug in gladstone that must be fixed. As such, it is ok if this
// tears down the extension service in OOP.
if (!_assemblyFilePathToHandlers.TryGetValue(assemblyFilePath, out var lazyHandlers))
throw new InvalidOperationException($"Extension '{assemblyFilePath}' was not registered.");
throw new InvalidOperationException(string.Format(FeaturesResources.Extension_0_was_not_registered, assemblyFilePath));

// Handlers already encapsulates any extension-level exceptions that occurred when loading the assembly.
// As such, we don't need our own try/catch here. We can just return the result directly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private sealed partial class ExtensionMessageHandlerService(
private static string GetAssemblyFolderPath(string assemblyFilePath)
{
return Path.GetDirectoryName(assemblyFilePath)
?? throw new InvalidOperationException($"Unable to get the directory name for {assemblyFilePath}.");
?? throw new InvalidOperationException(string.Format(FeaturesResources.Unable_to_get_the_directory_name_for_0, assemblyFilePath));
}

private void ClearCachedHandlers_WhileUnderLock()
Expand Down Expand Up @@ -114,7 +114,7 @@ private ValueTask UnregisterExtensionInCurrentProcessAsync(string assemblyFilePa
lock (_gate)
{
if (!_folderPathToExtensionFolder.TryGetValue(assemblyFolderPath, out var extensionFolder))
throw new InvalidOperationException($"No extension registered as '{assemblyFolderPath}'");
throw new InvalidOperationException(string.Format(FeaturesResources.No_extension_registered_as_0, assemblyFolderPath));

// Clear out the cached handler names. They will be recomputed the next time we need them.
ClearCachedHandlers_WhileUnderLock();
Expand Down Expand Up @@ -174,7 +174,7 @@ private async ValueTask<ExtensionMessageNames> GetExtensionMessageNamesInCurrent
// Throwing here indicates a bug in the gladstone client itself. So we want this to bubble outwards as a
// failure that disables extension running in the OOP process. This must be fixed by gladstone.
if (!_folderPathToExtensionFolder.TryGetValue(assemblyFolderPath, out var extensionFolder))
throw new InvalidOperationException($"No extensions registered at '{assemblyFolderPath}'");
throw new InvalidOperationException(string.Format(FeaturesResources.No_extensions_registered_at_0, assemblyFolderPath));

// Note if loading the extension assembly failed (due to issues in the extension itself), then the exception
// produced by it will be passed outwards as data in the ExtensionMessageNames result.
Expand Down Expand Up @@ -219,14 +219,14 @@ private async ValueTask<ExtensionMessageResult> HandleExtensionMessageInCurrentP
// bug in the gladstone client itself (as it allowed calling into an lsp message that never had
// registered handlers). So we want this to bubble outwards as a failure that disables extension
// running in the OOP process. This must be fixed by gladstone.
throw new InvalidOperationException($"No handler found for message {messageName}.");
throw new InvalidOperationException(string.Format(FeaturesResources.No_handler_found_for_message_0, messageName));
}

// Throwing here indicates a bug in the gladstone client itself (as it allowed calling into an lsp message
// that had multiple registered handlers). So we want this to bubble outwards as a failure that disables
// extension running in the OOP process. This must be fixed by gladstone.
if (handlers.Length > 1)
throw new InvalidOperationException($"Multiple handlers found for message {messageName}.");
throw new InvalidOperationException(string.Format(FeaturesResources.Multiple_handlers_found_for_message_0, messageName));

var handler = (IExtensionMessageHandlerWrapper<TArgument>)handlers[0];

Expand Down
21 changes: 21 additions & 0 deletions src/Features/Core/Portable/FeaturesResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3199,4 +3199,25 @@ Zero-width positive lookbehind assertions are typically used at the beginning of
<value>Convert to 'field' property</value>
<comment>{Locked="field"} "field" is C# keyword and should not be localized.</comment>
</data>
<data name="Extension_0_is_already_registered" xml:space="preserve">
<value>Extension '{0}' is already registered.</value>
</data>
<data name="Extension_0_was_not_registered" xml:space="preserve">
<value>Extension '{0}' was not registered.</value>
</data>
<data name="Unable_to_get_the_directory_name_for_0" xml:space="preserve">
<value>Unable to get the directory name for {0}.</value>
</data>
<data name="No_extension_registered_as_0" xml:space="preserve">
<value>No extension registered as '{0}'.</value>
</data>
<data name="No_extensions_registered_at_0" xml:space="preserve">
<value>No extensions registered at '{0}'.</value>
</data>
<data name="No_handler_found_for_message_0" xml:space="preserve">
<value>No handler found for message {0}.</value>
</data>
<data name="Multiple_handlers_found_for_message_0" xml:space="preserve">
<value>Multiple handlers found for message {0}.</value>
</data>
</root>
35 changes: 35 additions & 0 deletions src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions src/Features/Core/Portable/xlf/FeaturesResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions src/Features/Core/Portable/xlf/FeaturesResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading