{"id":9151,"date":"2006-12-07T12:42:00","date_gmt":"2006-12-07T12:42:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/12\/07\/resolve-error\/"},"modified":"2019-02-18T13:21:05","modified_gmt":"2019-02-18T20:21:05","slug":"resolve-error","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/resolve-error\/","title":{"rendered":"Resolve-Error"},"content":{"rendered":"<p>Recently I posted the following to the Microsoft.Public.Windows.PowerShell newsgroup (which&nbsp;you should&nbsp;participate in if you are not yet)&nbsp;<\/p>\n<blockquote>\n<p>Below is a function that I encourage you to add to your Profile files and <br \/>then use when reporting an error or ask a question about a exception you are <br \/>seeing.&nbsp; This function provides all the information we have about the error <br \/>message making it easier to diagnose what is actually going on.<\/p>\n<p>function Resolve-Error ($ErrorRecord=$Error[0])<br \/>{<br \/>&nbsp;&nbsp; $ErrorRecord | Format-List * -Force<br \/>&nbsp;&nbsp; $ErrorRecord.InvocationInfo |Format-List *<br \/>&nbsp;&nbsp; $Exception = $ErrorRecord.Exception<br \/>&nbsp;&nbsp; for ($i = 0; $Exception; $i++, ($Exception = $Exception.InnerException))<br \/>&nbsp;&nbsp; {&nbsp;&nbsp; &#8220;$i&#8221; * 80<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Exception |Format-List * -Force<br \/>&nbsp;&nbsp; }<br \/>}<br \/>Set-Alias rver Resolve-Error<\/p>\n<\/blockquote>\n<p>This brings up a couple of questions I thought I would respond to.<\/p>\n<p><strong>1. Why did we have to use -FORCE with Format-List?<br \/><\/strong><br \/>Errors generate ErrorRecords:<\/p>\n<p>[596:0]PS&gt; $error[0] |gm -MemberType Property<\/p>\n<p>&nbsp;&nbsp; TypeName: System.Management.Automation.ErrorRecord<\/p>\n<p>Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MemberType Definition<br \/>&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br \/>CategoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Management.Automation.ErrorCateg&#8230;<br \/>ErrorDetails&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Management.Automation.ErrorDetai&#8230;<br \/>Exception&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Exception Exception {get;}<br \/>FullyQualifiedErrorId Property&nbsp;&nbsp; System.String FullyQualifiedErrorId {get;}<br \/>InvocationInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Management.Automation.Invocation&#8230;<br \/>TargetObject&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; System.Object TargetObject {get;}<\/p>\n<p>These ErrorRecords get passed to the Output Stream just as the results of a command do.&nbsp; The formatting commands are hardwired to recognize these objects and treat them specially. They will treat them specially UNLESS you tell them not to with -FORCE.&nbsp; Let me show you:<\/p>\n<p>[596:0]PS&gt; cd NoSuchDir<br \/>Set-Location : Cannot find path &#8216;C:\\jps\\NoSuchDir&#8217; because it does not exis<br \/>t.<br \/>At line:1 char:3<br \/>+ cd&nbsp; &lt;&lt;&lt;&lt; NoSuchDir<br \/>[596:0]PS&gt; $error[0] |Format-List CategoryInfo,TargetObject<br \/>Set-Location : Cannot find path &#8216;C:\\jps\\NoSuchDir&#8217; because it does not exis<br \/>t.<br \/>At line:1 char:3<br \/>+ cd&nbsp; &lt;&lt;&lt;&lt; NoSuchDir<br \/>[596:0]PS&gt; $error[0] |Format-List CategoryInfo,TargetObject -Force<\/p>\n<p>CategoryInfo : ObjectNotFound: (C:\\jps\\NoSuchDir:String) [Set-Location], It<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; emNotFoundException<br \/>TargetObject : C:\\jps\\NoSuchDir<\/p>\n<p>&nbsp;<\/p>\n<p><strong>2. Why use the verb RESOLVE<\/strong><\/p>\n<p>Verb names&nbsp;are designed to be simultaneously&nbsp;specific and vague.&nbsp; They need to be specific enough that people can learn the meanings and have them stick and be used as the basis for guessing about what to do.&nbsp; They need to be vague enough so that they cover a wide range of things so we don&#8217;t end up with zillions of &#8220;precise&#8221; terms (&#8220;oh well you see, &#8216;kill&#8217; is different than &#8216;stop'&#8221;.&nbsp; &#8220;actually we &#8216;terminate'&#8221;, &#8220;my product &#8216;ceases&#8217; operations, &#8221; &#8216;quit&#8217; is a bit more accurate, &#8211; you can almost see the conversations in you head).<\/p>\n<p>Here is a pointer to the VerbNames and their meanings: <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms714428.aspx\">http:\/\/msdn2.microsoft.com\/en-us\/library\/ms714428.aspx<\/a><\/p>\n<p>&#8220;Resolve&#8221; is a diagnostic verb.&nbsp; It is used to&#8221;map a shorthand name to a long name&#8221;.&nbsp;&nbsp; What we are doing is mapping a digested &#8220;short&#8221; version of an error object to a fully articulated &#8220;long&#8221; version of that object for diagnostic purposes (to find out what is really going on).&nbsp;&nbsp; A reasonable person could have said that &#8220;Dump-Error&#8221; would be a better name but (AND THIS IS THE POINT) if we start argeeing to reasonable people about naming, we are going to end up with a zillion reasonable names.&nbsp; <\/p>\n<blockquote>\n<p>Local Optimization leads to global incoherence.<\/p>\n<\/blockquote>\n<p>Yes Resolve-Error&nbsp;may not be the most intuitive name right now.&nbsp; That&#8217;s because you haven&#8217;t being using Resolve-X, Resolve-Y, and Resolve-Z for the last couple of years.&nbsp; We (that&#8217;s <strong>us<\/strong> and <strong>you<\/strong>) need to be really hard-core about naming for the first couple of years or we&#8217;ll end up with world filled with &#8220;AWK&#8221;s.&nbsp; <\/p>\n<blockquote>\n<p>For those of you who don&#8217;t already know this, AWK is the first letters of the 3 guys that worked on it (<strong>A<\/strong>ho, <strong>W<\/strong>einberger, and <strong>K<\/strong>errigan).&nbsp; I love those guys and the fabulous work that they did.&nbsp; So here is the lesson &#8211; if you want to honor or remember&nbsp;someone &#8211;&nbsp;build a statue, don&#8217;t&nbsp;screw up&nbsp;the command naming.&nbsp; \ud83d\ude42<\/p>\n<\/blockquote>\n<p>Apologies for all the tangents today.<br \/>Enjoy!<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows PowerShell\/Aspen Architect<br \/>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at:&nbsp; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I posted the following to the Microsoft.Public.Windows.PowerShell newsgroup (which&nbsp;you should&nbsp;participate in if you are not yet)&nbsp; Below is a function that I encourage you to add to your Profile files and then use when reporting an error or ask a question about a exception you are seeing.&nbsp; This function provides all the information we [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9151","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Recently I posted the following to the Microsoft.Public.Windows.PowerShell newsgroup (which&nbsp;you should&nbsp;participate in if you are not yet)&nbsp; Below is a function that I encourage you to add to your Profile files and then use when reporting an error or ask a question about a exception you are seeing.&nbsp; This function provides all the information we [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=9151"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9151\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=9151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=9151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=9151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}