protected async Task HandleSetVariablesRequestAsync(
            SetVariableRequestArguments setVariableParams,
            RequestContext <SetVariableResponseBody> requestContext)
        {
            try
            {
                string updatedValue =
                    await _editorSession.DebugService.SetVariableAsync(
                        setVariableParams.VariablesReference,
                        setVariableParams.Name,
                        setVariableParams.Value);

                var setVariableResponse = new SetVariableResponseBody
                {
                    Value = updatedValue
                };

                await requestContext.SendResultAsync(setVariableResponse);
            }
            catch (Exception ex) when(ex is ArgumentTransformationMetadataException ||
                                      ex is InvalidPowerShellExpressionException ||
                                      ex is SessionStateUnauthorizedAccessException)
            {
                // Catch common, innocuous errors caused by the user supplying a value that can't be converted or the variable is not settable.
                Logger.Write(LogLevel.Verbose, $"Failed to set variable: {ex.Message}");
                await requestContext.SendErrorAsync(ex.Message);
            }
            catch (Exception ex)
            {
                Logger.Write(LogLevel.Error, $"Unexpected error setting variable: {ex.Message}");
                string msg =
                    $"Unexpected error: {ex.GetType().Name} - {ex.Message}  Please report this error to the PowerShellEditorServices project on GitHub.";
                await requestContext.SendErrorAsync(msg);
            }
        }
Beispiel #2
0
 public SetVariableResponse(SetVariableRequest request, bool success, SetVariableResponseBody body, string message = null)
     : base(request, success, body, message)
 {
 }
Beispiel #3
0
 internal SetVariableResponse(long req_seq, bool success, SetVariableResponseBody body, string message)
     : base(req_seq, "setVariable", success, body, message)
 {
 }