/// <summary> /// TraceErrorRecord /// </summary> public bool TraceErrorRecord(ErrorRecord errorRecord) { if (errorRecord != null) { Exception exception = errorRecord.Exception; string innerException = "None"; if (exception.InnerException != null) { innerException = exception.InnerException.Message; } ErrorCategoryInfo cinfo = errorRecord.CategoryInfo; string message = "None"; if (errorRecord.ErrorDetails != null) { message = errorRecord.ErrorDetails.Message; } return(DebugChannel.TraceError(PowerShellTraceEvent.ErrorRecord, PowerShellTraceOperationCode.Exception, PowerShellTraceTask.None, message, cinfo.Category.ToString(), cinfo.Reason, cinfo.TargetName, errorRecord.FullyQualifiedErrorId, exception.Message, exception.StackTrace, innerException)); } else { return(DebugChannel.TraceError(PowerShellTraceEvent.ErrorRecord, PowerShellTraceOperationCode.Exception, PowerShellTraceTask.None, "NULL errorRecord")); } }
private void InitializeErrorRecord(CimJobContext jobContext, CimException cimException) { string cmdletizationClassName; CimJobException cimJobException = this; CimJobContext cimJobContext = jobContext; CimException cimException1 = cimException; string messageId = cimException.MessageId; string str = messageId; if (messageId == null) { str = string.Concat("MiClientApiError_", cimException.NativeErrorCode); } cimJobException.InitializeErrorRecordCore(cimJobContext, cimException1, str, CimJobException.ConvertCimExceptionToErrorCategory(cimException)); if (cimException.ErrorData != null) { this.errorRecord.CategoryInfo.TargetName = cimException.ErrorSource; ErrorCategoryInfo categoryInfo = this.errorRecord.CategoryInfo; if (jobContext != null) { cmdletizationClassName = jobContext.CmdletizationClassName; } else { cmdletizationClassName = null; } categoryInfo.TargetType = cmdletizationClassName; } }
/// <summary> /// Creates a rich information exception object based on a full error record as recorded by PowerShell /// </summary> /// <param name="Record">The error record to copy from</param> public DbatoolsException(ErrorRecord Record) : this(Record.Exception) { CategoryInfo = Record.CategoryInfo; ErrorDetails = Record.ErrorDetails; FullyQualifiedErrorId = Record.FullyQualifiedErrorId; InvocationInfo = Record.InvocationInfo; ScriptStackTrace = Record.ScriptStackTrace; TargetObject = Record.TargetObject; }
public void ErrorRecordCreatedWithOperationTimeoutCategoryShouldHaveCategoryInfo() { var expectedCategory = ErrorCategory.OperationTimeout; var exception = new ApplicationException("Test"); var errorRecord = new ErrorRecord(exception, "ErrorId", expectedCategory, null); ErrorCategoryInfo categoryInfo = errorRecord.CategoryInfo; Assert.AreEqual(expectedCategory, categoryInfo.Category); Assert.AreEqual(string.Empty, categoryInfo.Activity); Assert.AreEqual(string.Empty, categoryInfo.TargetName); Assert.AreEqual(string.Empty, categoryInfo.TargetType); Assert.AreEqual("ApplicationException", categoryInfo.Reason); }
/// <summary> /// Create a filled out error record /// </summary> /// <param name="Record">The original error record</param> /// <param name="FunctionName">The function that wrote the error</param> /// <param name="Timestamp">When was the error generated</param> /// <param name="Message">What message was passed when writing the error</param> public DbaErrorRecord(ErrorRecord Record, string FunctionName, DateTime Timestamp, string Message) { this.FunctionName = FunctionName; this.Timestamp = Timestamp; this.Message = Message; CategoryInfo = Record.CategoryInfo; ErrorDetails = Record.ErrorDetails; Exception = Record.Exception; FullyQualifiedErrorId = Record.FullyQualifiedErrorId; InvocationInfo = Record.InvocationInfo; ScriptStackTrace = Record.ScriptStackTrace; TargetObject = Record.TargetObject; }
public bool TraceErrorRecord(ErrorRecord errorRecord) { if (errorRecord != null) { Exception exception = errorRecord.Exception; string message = "None"; if (exception.InnerException != null) { message = exception.InnerException.Message; } ErrorCategoryInfo categoryInfo = errorRecord.CategoryInfo; string str2 = "None"; if (errorRecord.ErrorDetails != null) { str2 = errorRecord.ErrorDetails.Message; } return(this.debugChannel.TraceError(PowerShellTraceEvent.ErrorRecord, PowerShellTraceOperationCode.Exception, PowerShellTraceTask.None, new object[] { str2, categoryInfo.Category.ToString(), categoryInfo.Reason, categoryInfo.TargetName, errorRecord.FullyQualifiedErrorId, exception.Message, exception.StackTrace, message })); } return(this.debugChannel.TraceError(PowerShellTraceEvent.ErrorRecord, PowerShellTraceOperationCode.Exception, PowerShellTraceTask.None, new object[] { "NULL errorRecord" })); }