Stops OE from breaking when paused DBs are expanded (#2083)

* Send session failed notification for paused DBs

* Creates error node when connections fail

* Revert "Send session failed notification for paused DBs"

This reverts commit 1f09d8adf9aadb61a7644f84f40558710b0ba5f2.

* Adjusts error node label

* Code clean up

* Update src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>

* Cleans up error node info creation

* Rename create error node method

---------

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
Lewis Sanchez
2023-06-02 12:29:52 -07:00
committed by GitHub
parent 37469dcbbd
commit 0b247e507e
2 changed files with 38 additions and 2 deletions

View File

@@ -78,6 +78,31 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Contracts
public NodeFilterProperty[] FilterableProperties { get; set; }
}
/// <summary>
/// Creates a NodeInfo and configures it for error situations
/// </summary>
public static class ErrorNodeInfo
{
/// <summary>
/// Helper function to create an error node.
/// </summary>
/// <param name="parentNodePath">The parent node the error node will appear under</param>
/// <param name="errorMessage">The error message to display in the error node</param>
/// <returns>NodeInfo instance with the specified parent path and error message</returns>
public static NodeInfo Create(string parentNodePath, string errorMessage)
{
return new NodeInfo()
{
ParentNodePath = parentNodePath,
ErrorMessage = errorMessage,
Label = errorMessage,
ObjectType = "error",
NodeType = "error",
IsLeaf = true
};
}
}
/// <summary>
/// The filterable properties that a node supports
/// </summary>

View File

@@ -1,4 +1,4 @@
//
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
@@ -453,8 +453,19 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
else
{
Logger.Verbose($"Expanding {nodePath}");
try
{
nodes = node.Expand(cancelToken, securityToken?.Token, filters).Select(x => x.ToNodeInfo()).ToArray();
}
catch (ConnectionFailureException ex)
{
var errorMessage = ex.InnerException?.Message ?? ex.Message;
Logger.Error($"Failed to expand node: {errorMessage}");
var errorNode = ErrorNodeInfo.Create(parentNodePath: nodePath, errorMessage: errorMessage);
nodes = new NodeInfo[] { errorNode };
}
}
response.Nodes = nodes;
response.ErrorMessage = node.ErrorMessage;
try