bin/projects/dbatools/dbatools/dbaSystem/DbaErrorRecord.cs

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
using System;
using System.Management.Automation;
 
namespace Sqlcollaborative.Dbatools.dbaSystem
{
    /// <summary>
    /// An error record written by dbatools
    /// </summary>
    [Serializable]
    public class DbaErrorRecord
    {
        /// <summary>
        /// The category of the error
        /// </summary>
        public ErrorCategoryInfo CategoryInfo;
 
        /// <summary>
        /// The details on the error
        /// </summary>
        public ErrorDetails ErrorDetails;
 
        /// <summary>
        /// The actual exception thrown
        /// </summary>
        public Exception Exception;
 
        /// <summary>
        /// The specific error identity, used to identify the target
        /// </summary>
        public string FullyQualifiedErrorId;
 
        /// <summary>
        /// The details of how this was called.
        /// </summary>
        public object InvocationInfo;
 
        /// <summary>
        /// The script's stacktrace
        /// </summary>
        public string ScriptStackTrace;
 
        /// <summary>
        /// The object being processed
        /// </summary>
        public object TargetObject;
 
        /// <summary>
        /// The name of the function throwing the error
        /// </summary>
        public string FunctionName;
 
        /// <summary>
        /// When was the error thrown
        /// </summary>
        public DateTime Timestamp;
 
        /// <summary>
        /// The message that was written in a userfriendly manner
        /// </summary>
        public string Message;
 
        /// <summary>
        /// The runspace the error occured on.
        /// </summary>
        public Guid Runspace;
 
        /// <summary>
        /// Create an empty record
        /// </summary>
        public DbaErrorRecord()
        {
 
        }
 
        /// <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;
        }
 
        /// <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>
        /// <param name="Runspace">The ID of the runspace writing the error. Used to separate output between different runspaces in the same process.</param>
        public DbaErrorRecord(ErrorRecord Record, string FunctionName, DateTime Timestamp, string Message, Guid Runspace)
        {
            this.FunctionName = FunctionName;
            this.Timestamp = Timestamp;
            this.Message = Message;
            this.Runspace = Runspace;
 
            CategoryInfo = Record.CategoryInfo;
            ErrorDetails = Record.ErrorDetails;
            Exception = Record.Exception;
            FullyQualifiedErrorId = Record.FullyQualifiedErrorId;
            InvocationInfo = Record.InvocationInfo;
            ScriptStackTrace = Record.ScriptStackTrace;
            TargetObject = Record.TargetObject;
        }
    }
}