mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-27 01:25:42 -05:00
Send Error Object on SendError (#304)
This change ensures that when calling `requestContext.SendError` you are only able to supply parameters that match the language service beta protocol expected Error object. In other words, you have to provide an error message and optionally and error code. # **BREAKING API CHANGES** This will break displaying errors in Microsoft/vscode-mssql. I will be making changes to properly handle the error object shortly. * Adding contract for returning Error objects as per LanguageService "protocol" * Fixes throughout codebase to send only error message in error cases Cleanup of CredentialServiceTest unit test class Adding standard error handling for event flow validator * Adding optional data field as per protocol spec https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md * Adding optional validation for error objects
This commit is contained in:
29
src/Microsoft.SqlTools.Hosting/Hosting/Contracts/Error.cs
Normal file
29
src/Microsoft.SqlTools.Hosting/Hosting/Contracts/Error.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
|
||||
namespace Microsoft.SqlTools.Hosting.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the message contract for errors returned via SendError.
|
||||
/// </summary>
|
||||
public class Error
|
||||
{
|
||||
/// <summary>
|
||||
/// Error code. If omitted will default to 0
|
||||
/// </summary>
|
||||
public int Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional information to return with the error
|
||||
/// </summary>
|
||||
public object Data { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Error message
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,10 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
using Error = Microsoft.SqlTools.Hosting.Contracts.Error;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Microsoft.SqlTools.Hosting.Protocol
|
||||
@@ -37,13 +39,26 @@ namespace Microsoft.SqlTools.Hosting.Protocol
|
||||
eventParams);
|
||||
}
|
||||
|
||||
public virtual async Task SendError(object errorDetails)
|
||||
public virtual Task SendError(string errorMessage, int errorCode = 0, object data = null)
|
||||
{
|
||||
await this.messageWriter.WriteMessage(
|
||||
// Build the error message
|
||||
Error error = new Error
|
||||
{
|
||||
Message = errorMessage,
|
||||
Code = errorCode,
|
||||
Data = data
|
||||
};
|
||||
return this.messageWriter.WriteMessage(
|
||||
Message.ResponseError(
|
||||
requestMessage.Id,
|
||||
requestMessage.Method,
|
||||
JToken.FromObject(errorDetails)));
|
||||
JToken.FromObject(error)));
|
||||
}
|
||||
|
||||
public virtual Task SendError(Exception e)
|
||||
{
|
||||
// Overload to use the parameterized error handler
|
||||
return SendError(e.Message, e.HResult, e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user