MegaBites-AI/Windows-powershell
0372
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Diagnostics.CodeAnalysis;5using System.Management.Automation.Internal;6using System.Runtime.Serialization;7 8namespace System.Management.Automation9{10 /// <summary>11 /// Defines the exception thrown for all Metadata errors.12 /// </summary>13 public class MetadataException : RuntimeException14 {15 internal const string MetadataMemberInitialization = "MetadataMemberInitialization";16 internal const string BaseName = "Metadata";17 18 /// <summary>19 /// Initializes a new instance of MetadataException with serialization parameters.20 /// </summary>21 /// <param name="info">Serialization information.</param>22 /// <param name="context">Streaming context.</param>23 [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]24 protected MetadataException(SerializationInfo info, StreamingContext context)25 {26 throw new NotSupportedException();27 }28 29 /// <summary>30 /// Initializes a new instance of MetadataException with the message set31 /// to typeof(MetadataException).FullName.32 /// </summary>33 public MetadataException() : base(typeof(MetadataException).FullName)34 {35 SetErrorCategory(ErrorCategory.MetadataError);36 }37 38 /// <summary>39 /// Initializes a new instance of MetadataException setting the message.40 /// </summary>41 /// <param name="message">The exception's message.</param>42 public MetadataException(string message) : base(message)43 {44 SetErrorCategory(ErrorCategory.MetadataError);45 }46 47 /// <summary>48 /// Initializes a new instance of MetadataException setting the message and innerException.49 /// </summary>50 /// <param name="message">The exception's message.</param>51 /// <param name="innerException">The exception's inner exception.</param>52 public MetadataException(string message, Exception innerException) : base(message, innerException)53 {54 SetErrorCategory(ErrorCategory.MetadataError);55 }56 57 internal MetadataException(58 string errorId,59 Exception innerException,60 string resourceStr,61 params object[] arguments)62 : base(63 StringUtil.Format(resourceStr, arguments),64 innerException)65 {66 SetErrorCategory(ErrorCategory.MetadataError);67 SetErrorId(errorId);68 }69 }70 71 /// <summary>72 /// Defines the exception thrown for all Validate attributes.73 /// </summary>74 public class ValidationMetadataException : MetadataException75 {76 internal const string ValidateRangeElementType = "ValidateRangeElementType";77 internal const string ValidateRangePositiveFailure = "ValidateRangePositiveFailure";78 internal const string ValidateRangeNonNegativeFailure = "ValidateRangeNonNegativeFailure";79 internal const string ValidateRangeNegativeFailure = "ValidateRangeNegativeFailure";80 internal const string ValidateRangeNonPositiveFailure = "ValidateRangeNonPositiveFailure";81 internal const string ValidateRangeMinRangeMaxRangeType = "ValidateRangeMinRangeMaxRangeType";82 internal const string ValidateRangeNotIComparable = "ValidateRangeNotIComparable";83 internal const string ValidateRangeMaxRangeSmallerThanMinRange = "ValidateRangeMaxRangeSmallerThanMinRange";84 internal const string ValidateRangeGreaterThanMaxRangeFailure = "ValidateRangeGreaterThanMaxRangeFailure";85 internal const string ValidateRangeSmallerThanMinRangeFailure = "ValidateRangeSmallerThanMinRangeFailure";86 87 internal const string ValidateFailureResult = "ValidateFailureResult";88 89 internal const string ValidatePatternFailure = "ValidatePatternFailure";90 internal const string ValidateScriptFailure = "ValidateScriptFailure";91 92 internal const string ValidateCountNotInArray = "ValidateCountNotInArray";93 internal const string ValidateCountMaxLengthSmallerThanMinLength = "ValidateCountMaxLengthSmallerThanMinLength";94 internal const string ValidateCountMinLengthFailure = "ValidateCountMinLengthFailure";95 internal const string ValidateCountMaxLengthFailure = "ValidateCountMaxLengthFailure";96 97 internal const string ValidateLengthMaxLengthSmallerThanMinLength = "ValidateLengthMaxLengthSmallerThanMinLength";98 internal const string ValidateLengthNotString = "ValidateLengthNotString";99 internal const string ValidateLengthMinLengthFailure = "ValidateLengthMinLengthFailure";100 internal const string ValidateLengthMaxLengthFailure = "ValidateLengthMaxLengthFailure";101 internal const string ValidateSetFailure = "ValidateSetFailure";102 internal const string ValidateVersionFailure = "ValidateVersionFailure";103 internal const string InvalidValueFailure = "InvalidValueFailure";104 105 /// <summary>106 /// Initializes a new instance of ValidationMetadataException with serialization parameters.107 /// </summary>108 /// <param name="info">Serialization information.</param>109 /// <param name="context">Streaming context.</param>110 [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]111 protected ValidationMetadataException(SerializationInfo info, StreamingContext context)112 {113 throw new NotSupportedException();114 }115 116 /// <summary>117 /// Initializes a new instance of ValidationMetadataException with the message set118 /// to typeof(ValidationMetadataException).FullName.119 /// </summary>120 public ValidationMetadataException() : base(typeof(ValidationMetadataException).FullName) { }121 /// <summary>122 /// Initializes a new instance of ValidationMetadataException setting the message.123 /// </summary>124 /// <param name="message">The exception's message.</param>125 public ValidationMetadataException(string message) : this(message, false) { }126 /// <summary>127 /// Initializes a new instance of ValidationMetadataException setting the message and innerException.128 /// </summary>129 /// <param name="message">The exception's message.</param>130 /// <param name="innerException">The exception's inner exception.</param>131 public ValidationMetadataException(string message, Exception innerException) : base(message, innerException) { }132 133 internal ValidationMetadataException(134 string errorId,135 Exception innerException,136 string resourceStr,137 params object[] arguments)138 : base(errorId, innerException, resourceStr, arguments)139 {140 }141 142 /// <summary>143 /// Initialize a new instance of ValidationMetadataException. This validation exception could be144 /// ignored in positional binding phase if the <para>swallowException</para> is set to be true.145 /// </summary>146 /// <param name="message">147 /// The error message</param>148 /// <param name="swallowException">149 /// Indicate whether to swallow this exception in positional binding phase150 /// </param>151 internal ValidationMetadataException(string message, bool swallowException) : base(message)152 {153 _swallowException = swallowException;154 }155 156 /// <summary>157 /// Make the positional binding swallow this exception when it's set to true.158 /// </summary>159 /// <remarks>160 /// This property is only used internally in the positional binding phase161 /// </remarks>162 internal bool SwallowException163 {164 get { return _swallowException; }165 }166 167 private readonly bool _swallowException = false;168 }169 170 /// <summary>171 /// Defines the exception thrown for all ArgumentTransformation attributes.172 /// </summary>173 public class ArgumentTransformationMetadataException : MetadataException174 {175 internal const string ArgumentTransformationArgumentsShouldBeStrings = "ArgumentTransformationArgumentsShouldBeStrings";176 177 /// <summary>178 /// Initializes a new instance of ArgumentTransformationMetadataException with serialization parameters.179 /// </summary>180 /// <param name="info">Serialization information.</param>181 /// <param name="context">Streaming context.</param>182 [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]183 protected ArgumentTransformationMetadataException(SerializationInfo info, StreamingContext context)184 {185 throw new NotSupportedException();186 }187 188 /// <summary>189 /// Initializes a new instance of ArgumentTransformationMetadataException with the message set190 /// to typeof(ArgumentTransformationMetadataException).FullName.191 /// </summary>192 public ArgumentTransformationMetadataException()193 : base(typeof(ArgumentTransformationMetadataException).FullName) { }194 195 /// <summary>196 /// Initializes a new instance of ArgumentTransformationMetadataException setting the message.197 /// </summary>198 /// <param name="message">The exception's message.</param>199 public ArgumentTransformationMetadataException(string message)200 : base(message) { }201 202 /// <summary>203 /// Initializes a new instance of ArgumentTransformationMetadataException setting the message and innerException.204 /// </summary>205 /// <param name="message">The exception's message.</param>206 /// <param name="innerException">The exception's inner exception.</param>207 public ArgumentTransformationMetadataException(string message, Exception innerException)208 : base(message, innerException) { }209 210 internal ArgumentTransformationMetadataException(211 string errorId,212 Exception innerException,213 string resourceStr,214 params object[] arguments)215 : base(errorId, innerException, resourceStr, arguments)216 {217 }218 }219 220 /// <summary>221 /// Defines the exception thrown for all parameter binding exceptions related to metadata attributes.222 /// </summary>223 public class ParsingMetadataException : MetadataException224 {225 internal const string ParsingTooManyParameterSets = "ParsingTooManyParameterSets";226 227 /// <summary>228 /// Initializes a new instance of ParsingMetadataException with serialization parameters.229 /// </summary>230 /// <param name="info">Serialization information.</param>231 /// <param name="context">Streaming context.</param>232 [Obsolete("Legacy serialization support is deprecated since .NET 8", DiagnosticId = "SYSLIB0051")]233 protected ParsingMetadataException(SerializationInfo info, StreamingContext context)234 {235 throw new NotSupportedException();236 }237 238 /// <summary>239 /// Initializes a new instance of ParsingMetadataException with the message set240 /// to typeof(ParsingMetadataException).FullName.241 /// </summary>242 public ParsingMetadataException()243 : base(typeof(ParsingMetadataException).FullName) { }244 245 /// <summary>246 /// Initializes a new instance of ParsingMetadataException setting the message.247 /// </summary>248 /// <param name="message">The exception's message.</param>249 public ParsingMetadataException(string message)250 : base(message) { }251 252 /// <summary>253 /// Initializes a new instance of ParsingMetadataException setting the message and innerException.254 /// </summary>255 /// <param name="message">The exception's message.</param>256 /// <param name="innerException">The exception's inner exception.</param>257 public ParsingMetadataException(string message, Exception innerException)258 : base(message, innerException) { }259 260 internal ParsingMetadataException(261 string errorId,262 Exception innerException,263 string resourceStr,264 params object[] arguments)265 : base(errorId, innerException, resourceStr, arguments)266 {267 }268 }269}270 