fix drop object issue and add logging (#1974)

* fix drop object issue

* remove content logging

* remove ununsed using.
This commit is contained in:
Alan Ren
2023-03-28 19:55:37 -07:00
committed by GitHub
parent 45f1d0db22
commit 3ddbf729ce
2 changed files with 12 additions and 9 deletions

View File

@@ -159,24 +159,27 @@ namespace Microsoft.SqlTools.Hosting.Protocol
}
catch (Exception ex)
{
string errorMessage = GetErrorMessage(ex);
Logger.Error($"{requestType.MethodName} : {errorMessage}");
await requestContext.SendError(errorMessage);
Logger.Error($"{requestType.MethodName} : {GetErrorMessage(ex, true)}");
await requestContext.SendError(GetErrorMessage(ex));
}
});
}
private string GetErrorMessage(Exception e)
private string GetErrorMessage(Exception e, bool includeStackTrace = false)
{
List<string> errors = new List<string>();
while (e != null)
{
errors.Add(e.Message);
if (includeStackTrace)
{
errors.Add(e.StackTrace);
}
e = e.InnerException;
}
return errors.Count > 0 ? string.Join(" ---> ", errors) : string.Empty;
return errors.Count > 0 ? string.Join(includeStackTrace ? Environment.NewLine : " ---> ", errors) : string.Empty;
}
public void SetEventHandler<TParams>(

View File

@@ -96,7 +96,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
}
catch (FailedOperationException ex)
{
if (ex.InnerException is MissingObjectException && requestParams.ThrowIfNotExist)
if (!(ex.InnerException is MissingObjectException) || (ex.InnerException is MissingObjectException && requestParams.ThrowIfNotExist))
{
throw;
}