File size: 23,770 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 | // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Management.Automation.Internal;
using System.Runtime.Serialization;
using System.Security.Permissions;
namespace System.Management.Automation.Remoting
{
/// <summary>
/// This enum defines the error message ids used by the resource manager to get
/// localized messages.
///
/// Related error ids are organized in a pre-defined range of values.
/// </summary>
internal enum PSRemotingErrorId : uint
{
// OS related 1-9
DefaultRemotingExceptionMessage = 0,
OutOfMemory = 1,
UnsupportedOSForRemoteEnumeration = 2,
// Pipeline related range: 10-99
PipelineIdsDoNotMatch = 10,
PipelineNotFoundOnServer = 11,
PipelineStopped = 12,
// Runspace, Host, UI and RawUI related range: 200-299
RunspaceAlreadyExists = 200,
RunspaceIdsDoNotMatch = 201,
RemoteRunspaceOpenFailed = 202,
RunspaceCannotBeFound = 203,
ResponsePromptIdCannotBeFound = 204,
RemoteHostCallFailed = 205,
RemoteHostMethodNotImplemented = 206,
RemoteHostDataEncodingNotSupported = 207,
RemoteHostDataDecodingNotSupported = 208,
NestedPipelineNotSupported = 209,
RelativeUriForRunspacePathNotSupported = 210,
RemoteHostDecodingFailed = 211,
MustBeAdminToOverrideThreadOptions = 212,
RemoteHostPromptForCredentialModifiedCaption = 213,
RemoteHostPromptForCredentialModifiedMessage = 214,
RemoteHostReadLineAsSecureStringPrompt = 215,
RemoteHostGetBufferContents = 216,
RemoteHostPromptSecureStringPrompt = 217,
WinPERemotingNotSupported = 218,
// reserved range: 300-399
// Encoding/Decoding and fragmentation related range: 400-499
ReceivedUnsupportedRemoteHostCall = 400,
ReceivedUnsupportedAction = 401,
ReceivedUnsupportedDataType = 402,
MissingDestination = 403,
MissingTarget = 404,
MissingRunspaceId = 405,
MissingDataType = 406,
MissingCallId = 407,
MissingMethodName = 408,
MissingIsStartFragment = 409,
MissingProperty = 410,
ObjectIdsNotMatching = 411,
FragmentIdsNotInSequence = 412,
ObjectIsTooBig = 413,
MissingIsEndFragment = 414,
DeserializedObjectIsNull = 415,
BlobLengthNotInRange = 416,
DecodingErrorForErrorRecord = 417,
DecodingErrorForPipelineStateInfo = 418,
DecodingErrorForRunspaceStateInfo = 419,
ReceivedUnsupportedRemotingTargetInterfaceType = 420,
UnknownTargetClass = 421,
MissingTargetClass = 422,
DecodingErrorForRunspacePoolStateInfo = 423,
DecodingErrorForMinRunspaces = 424,
DecodingErrorForMaxRunspaces = 425,
DecodingErrorForPowerShellStateInfo = 426,
DecodingErrorForThreadOptions = 427,
CantCastPropertyToExpectedType = 428,
CantCastRemotingDataToPSObject = 429,
CantCastCommandToPSObject = 430,
CantCastParameterToPSObject = 431,
ObjectIdCannotBeLessThanZero = 432,
NotEnoughHeaderForRemoteDataObject = 433,
// reserved range: 500-599
// Remote Session related range: 600-699
RemotingDestinationNotForMe = 600,
ClientNegotiationTimeout = 601,
ClientNegotiationFailed = 602,
ServerRequestedToCloseSession = 603,
ServerNegotiationFailed = 604,
ServerNegotiationTimeout = 605,
ClientRequestedToCloseSession = 606,
FatalErrorCausingClose = 607,
ClientKeyExchangeFailed = 608,
ServerKeyExchangeFailed = 609,
ClientNotFoundCapabilityProperties = 610,
ServerNotFoundCapabilityProperties = 611,
// reserved range: 700-799
// Transport related range: 800-899
ConnectFailed = 801,
CloseIsCalled = 802,
ForceClosed = 803,
CloseFailed = 804,
CloseCompleted = 805,
UnsupportedWaitHandleType = 806,
ReceivedDataStreamIsNotStdout = 807,
StdInIsNotOpen = 808,
NativeWriteFileFailed = 809,
NativeReadFileFailed = 810,
InvalidSchemeValue = 811,
ClientReceiveFailed = 812,
ClientSendFailed = 813,
CommandHandleIsNull = 814,
StdInCannotBeSetToNoWait = 815,
PortIsOutOfRange = 816,
ServerProcessExited = 817,
CannotGetStdInHandle = 818,
CannotGetStdOutHandle = 819,
CannotGetStdErrHandle = 820,
CannotSetStdInHandle = 821,
CannotSetStdOutHandle = 822,
CannotSetStdErrHandle = 823,
InvalidConfigurationName = 824,
ConnectSkipCheckFailed = 825,
// Error codes added to support new WSMan Fan-In Model API
CreateSessionFailed = 851,
CreateExFailed = 853,
ConnectExCallBackError = 854,
SendExFailed = 855,
SendExCallBackError = 856,
ReceiveExFailed = 857,
ReceiveExCallBackError = 858,
RunShellCommandExFailed = 859,
RunShellCommandExCallBackError = 860,
CommandSendExFailed = 861,
CommandSendExCallBackError = 862,
CommandReceiveExFailed = 863,
CommandReceiveExCallBackError = 864,
CloseExCallBackError = 866,
// END: Error codes added to support new WSMan Fan-In Model API
// BEGIN: Error IDs introduced for URI redirection
RedirectedURINotWellFormatted = 867,
URIEndPointNotResolved = 868,
// END: Error IDs introduced for URI redirection
// BEGIN: Error IDs introduced for Quota Management
ReceivedObjectSizeExceededMaximumClient = 869,
ReceivedDataSizeExceededMaximumClient = 870,
ReceivedObjectSizeExceededMaximumServer = 871,
ReceivedDataSizeExceededMaximumServer = 872,
// END: Error IDs introduced for Quota Management
// BEGIN: Error IDs introduced for startup script
StartupScriptThrewTerminatingError = 873,
// END: Error IDs introduced for startup script
TroubleShootingHelpTopic = 874,
// BEGIN: Error IDs introduced for disconnect/reconnect
DisconnectShellExFailed = 875,
DisconnectShellExCallBackErrr = 876,
ReconnectShellExFailed = 877,
ReconnectShellExCallBackErrr = 878,
// END: Error IDs introduced for disconnect/reconnect
// Cmdlets related range: 900-999
RemoteRunspaceInfoHasDuplicates = 900,
RemoteRunspaceInfoLimitExceeded = 901,
RemoteRunspaceOpenUnknownState = 902,
UriSpecifiedNotValid = 903,
RemoteRunspaceClosed = 904,
RemoteRunspaceNotAvailableForSpecifiedComputer = 905,
RemoteRunspaceNotAvailableForSpecifiedRunspaceId = 906,
StopPSJobWhatIfTarget = 907,
InvalidJobStateGeneral = 909,
JobWithSpecifiedNameNotFound = 910,
JobWithSpecifiedInstanceIdNotFound = 911,
JobWithSpecifiedSessionIdNotFound = 912,
JobWithSpecifiedNameNotCompleted = 913,
JobWithSpecifiedSessionIdNotCompleted = 914,
JobWithSpecifiedInstanceIdNotCompleted = 915,
RemovePSJobWhatIfTarget = 916,
ComputerNameParamNotSupported = 917,
RunspaceParamNotSupported = 918,
RemoteRunspaceNotAvailableForSpecifiedName = 919,
RemoteRunspaceNotAvailableForSpecifiedSessionId = 920,
ItemNotFoundInRepository = 921,
CannotRemoveJob = 922,
NewRunspaceAmbiguousAuthentication = 923,
WildCardErrorFilePathParameter = 924,
FilePathNotFromFileSystemProvider = 925,
FilePathShouldPS1Extension = 926,
PSSessionConfigurationName = 927,
PSSessionAppName = 928,
// Custom Shell commands
CSCDoubleParameterOutOfRange = 929,
URIRedirectionReported = 930,
NoMoreInputWrites = 931,
InvalidComputerName = 932,
ProxyAmbiguousAuthentication = 933,
ProxyCredentialWithoutAccess = 934,
// Start-PSSession related error codes.
PushedRunspaceMustBeOpen = 951,
HostDoesNotSupportPushRunspace = 952,
RemoteRunspaceHasMultipleMatchesForSpecifiedRunspaceId = 953,
RemoteRunspaceHasMultipleMatchesForSpecifiedSessionId = 954,
RemoteRunspaceHasMultipleMatchesForSpecifiedName = 955,
RemoteRunspaceDoesNotSupportPushRunspace = 956,
HostInNestedPrompt = 957,
InvalidVMId = 959,
InvalidVMNameNoVM = 960,
InvalidVMNameMultipleVM = 961,
HyperVModuleNotAvailable = 962,
InvalidUsername = 963,
InvalidCredential = 964,
VMSessionConnectFailed = 965,
InvalidContainerId = 966,
CannotCreateProcessInContainer = 967,
CannotTerminateProcessInContainer = 968,
ContainersFeatureNotEnabled = 969,
RemoteSessionHyperVSocketServerConstructorFailure = 970,
ContainerSessionConnectFailed = 973,
RemoteSessionHyperVSocketClientConstructorSetSocketOptionFailure = 974,
InvalidVMState = 975,
// Invoke-Command related error codes.
InvalidVMIdNotSingle = 981,
InvalidVMNameNotSingle = 982,
// SessionState Description related messages
WsmanMaxRedirectionCountVariableDescription = 1001,
PSDefaultSessionOptionDescription = 1002,
PSSenderInfoDescription = 1004,
// IPC for Background jobs related errors: 2000
IPCUnknownNodeType = 2001,
IPCInsufficientDataforElement = 2002,
IPCWrongAttributeCountForDataElement = 2003,
IPCOnlyTextExpectedInDataElement = 2004,
IPCWrongAttributeCountForElement = 2005,
IPCUnknownElementReceived = 2006,
IPCSupportsOnlyDefaultAuth = 2007,
IPCWowComponentNotPresent = 2008,
IPCServerProcessReportedError = 2100,
IPCServerProcessExited = 2101,
IPCErrorProcessingServerData = 2102,
IPCUnknownCommandGuid = 2103,
IPCNoSignalForSession = 2104,
IPCSignalTimedOut = 2105,
IPCCloseTimedOut = 2106,
IPCExceptionLaunchingProcess = 2107,
}
/// <summary>
/// This static class defines the resource base name used by remoting errors.
/// It also provides a convenience method to get the localized strings.
/// </summary>
internal static class PSRemotingErrorInvariants
{
/// <summary>
/// This method is a convenience method to retrieve the localized string.
/// </summary>
/// <param name="resourceString">
/// This parameter holds the string in the resource file.
/// </param>
/// <param name="args">
/// Optional parameters required by the resource string formatting information.
/// </param>
/// <returns>
/// The formatted localized string.
/// </returns>
internal static string FormatResourceString(string resourceString, params object[] args)
{
string resourceFormatedString = StringUtil.Format(resourceString, args);
return resourceFormatedString;
}
}
/// <summary>
/// This exception is used by remoting code to indicated a data structure handler related error.
/// </summary>
public class PSRemotingDataStructureException : RuntimeException
{
#region Constructors
/// <summary>
/// Default constructor.
/// </summary>
public PSRemotingDataStructureException()
: base(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.DefaultRemotingExceptionMessage, typeof(PSRemotingDataStructureException).FullName))
{
SetDefaultErrorRecord();
}
/// <summary>
/// This constructor takes a localized string as the error message.
/// </summary>
/// <param name="message">
/// A localized string as an error message.
/// </param>
public PSRemotingDataStructureException(string message)
: base(message)
{
SetDefaultErrorRecord();
}
/// <summary>
/// This constructor takes a localized string as the error message, and an inner exception.
/// </summary>
/// <param name="message">
/// A localized string as an error message.
/// </param>
/// <param name="innerException">
/// Inner exception.
/// </param>
public PSRemotingDataStructureException(string message, Exception innerException)
: base(message, innerException)
{
SetDefaultErrorRecord();
}
/// <summary>
/// This constructor takes an error id and optional parameters.
/// </summary>
/// <param name="resourceString">
/// The resource string in the base resource file.
/// </param>
/// <param name="args">
/// Optional parameters required to format the resource string.
/// </param>
internal PSRemotingDataStructureException(string resourceString, params object[] args)
: base(PSRemotingErrorInvariants.FormatResourceString(resourceString, args))
{
SetDefaultErrorRecord();
}
/// <summary>
/// This constructor takes an inner exception and an error id.
/// </summary>
/// <param name="innerException">
/// Inner exception.
/// </param>
/// <param name="resourceString">
/// The resource string in the base resource file.
/// </param>
/// <param name="args">
/// Optional parameters required to format the resource string.
/// </param>
internal PSRemotingDataStructureException(Exception innerException, string resourceString, params object[] args)
: base(PSRemotingErrorInvariants.FormatResourceString(resourceString, args), innerException)
{
SetDefaultErrorRecord();
}
/// <summary>
/// This constructor is required by serialization.
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
[Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]
protected PSRemotingDataStructureException(SerializationInfo info, StreamingContext context)
{
throw new NotSupportedException();
}
#endregion Constructors
/// <summary>
/// Set the default ErrorRecord.
/// </summary>
private void SetDefaultErrorRecord()
{
SetErrorCategory(ErrorCategory.ResourceUnavailable);
SetErrorId(typeof(PSRemotingDataStructureException).FullName);
}
}
/// <summary>
/// This exception is used by remoting code to indicate an error condition in network operations.
/// </summary>
public class PSRemotingTransportException : RuntimeException
{
private int _errorCode;
private string _transportMessage;
#region Constructors
/// <summary>
/// This is the default constructor.
/// </summary>
public PSRemotingTransportException()
: base(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.DefaultRemotingExceptionMessage, typeof(PSRemotingTransportException).FullName))
{
SetDefaultErrorRecord();
}
/// <summary>
/// This constructor takes a localized error message.
/// </summary>
/// <param name="message">
/// A localized error message.
/// </param>
public PSRemotingTransportException(string message)
: base(message)
{
SetDefaultErrorRecord();
}
/// <summary>
/// This constructor takes a localized message and an inner exception.
/// </summary>
/// <param name="message">
/// Localized error message.
/// </param>
/// <param name="innerException">
/// Inner exception.
/// </param>
public PSRemotingTransportException(string message, Exception innerException)
: base(message, innerException)
{
SetDefaultErrorRecord();
}
/// <summary>
/// This constructor takes an error id and optional parameters.
/// </summary>
/// <param name="errorId">
/// The error id in the base resource file.
/// </param>
/// <param name="resourceString">
/// The resource string in the base resource file.
/// </param>
/// <param name="args">
/// Optional parameters required to format the resource string.
/// </param>
internal PSRemotingTransportException(PSRemotingErrorId errorId, string resourceString, params object[] args)
: base(PSRemotingErrorInvariants.FormatResourceString(resourceString, args))
{
SetDefaultErrorRecord();
_errorCode = (int)errorId;
}
/// <summary>
/// This constructor takes an inner exception and an error id.
/// </summary>
/// <param name="innerException">
/// Inner exception.
/// </param>
/// <param name="resourceString">
/// The resource string in the base resource file.
/// </param>
/// <param name="args">
/// Optional parameters required to format the resource string.
/// </param>
internal PSRemotingTransportException(Exception innerException, string resourceString, params object[] args)
: base(PSRemotingErrorInvariants.FormatResourceString(resourceString, args), innerException)
{
SetDefaultErrorRecord();
}
/// <summary>
/// This constructor is required by serialization.
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
/// <exception cref="ArgumentNullException">
/// 1. info is null.
/// </exception>
[Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]
protected PSRemotingTransportException(SerializationInfo info, StreamingContext context)
{
throw new NotSupportedException();
}
#endregion Constructors
/// <summary>
/// Set the default ErrorRecord.
/// </summary>
protected void SetDefaultErrorRecord()
{
SetErrorCategory(ErrorCategory.ResourceUnavailable);
SetErrorId(typeof(PSRemotingDataStructureException).FullName);
}
/// <summary>
/// The error code from native library API call.
/// </summary>
public int ErrorCode
{
get
{
return _errorCode;
}
set
{
_errorCode = value;
}
}
/// <summary>
/// This the message from the native transport layer.
/// </summary>
public string TransportMessage
{
get
{
return _transportMessage;
}
set
{
_transportMessage = value;
}
}
}
/// <summary>
/// This exception is used by PowerShell's remoting infrastructure to notify a URI redirection
/// exception.
/// </summary>
public class PSRemotingTransportRedirectException : PSRemotingTransportException
{
#region Constructor
/// <summary>
/// This is the default constructor.
/// </summary>
public PSRemotingTransportRedirectException()
: base(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.DefaultRemotingExceptionMessage,
typeof(PSRemotingTransportRedirectException).FullName))
{
SetDefaultErrorRecord();
}
/// <summary>
/// This constructor takes a localized error message.
/// </summary>
/// <param name="message">
/// A localized error message.
/// </param>
public PSRemotingTransportRedirectException(string message)
: base(message)
{
}
/// <summary>
/// This constructor takes a localized message and an inner exception.
/// </summary>
/// <param name="message">
/// Localized error message.
/// </param>
/// <param name="innerException">
/// Inner exception.
/// </param>
public PSRemotingTransportRedirectException(string message, Exception innerException)
: base(message, innerException)
{
}
/// <summary>
/// This constructor takes an inner exception and an error id.
/// </summary>
/// <param name="innerException">
/// Inner exception.
/// </param>
/// <param name="resourceString">
/// The resource string in the base resource file.
/// </param>
/// <param name="args">
/// Optional parameters required to format the resource string.
/// </param>
internal PSRemotingTransportRedirectException(Exception innerException, string resourceString, params object[] args)
: base(innerException, resourceString, args)
{
}
/// <summary>
/// This constructor is required by serialization.
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
/// <exception cref="ArgumentNullException">
/// 1. info is null.
/// </exception>
[Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]
protected PSRemotingTransportRedirectException(SerializationInfo info, StreamingContext context)
{
throw new NotSupportedException();
}
/// <summary>
/// This constructor takes an redirect URI, error id and optional parameters.
/// </summary>
/// <param name="redirectLocation">
/// String specifying a redirect location.
/// </param>
/// <param name="errorId">
/// The error id in the base resource file.
/// </param>
/// <param name="resourceString">
/// The resource string in the base resource file.
/// </param>
/// <param name="args">
/// Optional parameters required to format the resource string.
/// </param>
internal PSRemotingTransportRedirectException(string redirectLocation, PSRemotingErrorId errorId, string resourceString, params object[] args)
: base(errorId, resourceString, args)
{
RedirectLocation = redirectLocation;
}
#endregion
#region Properties
/// <summary>
/// String specifying a redirect location.
/// </summary>
public string RedirectLocation { get; }
#endregion
}
/// <summary>
/// This exception is used by PowerShell Direct errors.
/// </summary>
public class PSDirectException : RuntimeException
{
#region Constructor
/// <summary>
/// This constructor takes a localized string as the error message.
/// </summary>
/// <param name="message">
/// A localized string as an error message.
/// </param>
public PSDirectException(string message)
: base(message)
{
}
#endregion Constructor
}
}
|