{"id":16895,"date":"2014-04-19T11:35:07","date_gmt":"2014-04-19T15:35:07","guid":{"rendered":"http:\/\/ssgreenberg.name\/PoliticsBlog\/?p=16895"},"modified":"2014-04-19T12:06:06","modified_gmt":"2014-04-19T16:06:06","slug":"programmers-how-not-to-write-an-error-message","status":"publish","type":"post","link":"https:\/\/ssgreenberg.name\/PoliticsBlog\/2014\/04\/19\/programmers-how-not-to-write-an-error-message\/","title":{"rendered":"Programmers: How Not To Write An Error Message"},"content":{"rendered":"<p>A friend called me to say that he could not play one of the YouTube videos on my blog.\u00a0 It would play for a few seconds and then he would get a message &#8220;An error occurred&#8221;.\u00a0 Along with the error message there were all sorts of suggestions as to what he could do to fix the error, but none of them worked.<\/p>\n<p>I had him repeat to me the exact words of the message.\u00a0 Googling <a title=\"Google search for the error\" href=\"https:\/\/www.google.com\/#q=youtube+an+error+occurred\" target=\"_blank\">youtube an error occurred<\/a> was enough to find the problem.\u00a0 I found the web page <a title=\"Web message thread about the error\" href=\"http:\/\/support.mozilla.org\/en-US\/questions\/975381\" target=\"_blank\">The dreaded &#8220;an error occurred&#8221; message shows on *every* YouTube video<\/a>.<\/p>\n<p>Eventually, it turned out that my friend did not have any speakers nor headphone connected to his computer, and that was the problem.\u00a0 This was mentioned in the thread about the error. I realized that if the YouTube message had said something like &#8220;An error occurred, I could not find the sound device,&#8221; he could have solved his problem himself without any need to call me.<\/p>\n<p>This leads me to one of the prime principles that I held to as a programmer.\u00a0 If you are\u00a0 going to write an error message about an error that has been detected, you owe it to\u00a0 the user to tell him or her exactly what was the error that you detected.<\/p>\n<p>Maybe the YouTube folks thought that they were being nice by telling you what things you might try in order to fix the unidentified error.\u00a0 The trouble is that no programmer can imagine all the things that might go wrong, nor all the reasons for them to go wrong.\u00a0 If you tell the user exactly what it was you detected, then the user may know what he or she did to cause the error.\u00a0 Or the user might consult with someone who would understand the details of the error as described in the message.<\/p>\n<p>When my friend told me that he had no speakers or headphones, my natural question was &#8220;Why would you do that?&#8221;\u00a0 He explained why he used headphones and not speakers and that he was just testing to see if he could watch the video before he plugged in his headphones.\u00a0 It was certainly a reasonable explanation, but not something I would have ever imagined.\u00a0 Which brings me to another oft heard response from other programmers\u00a0 when I insisted on good error messages and also allowing people to do things that you would never imagine them wanting to do.\u00a0 I would hear the old dreaded question, &#8220;Well, why would anybody want to do that?&#8221;\u00a0 My answer was &#8220;I have no idea, but what harm does it\u00a0 do if you to let them do it?&#8221;\u00a0 I had found over the years that customers could find amazing things to do with your program that you never dreamed of.<\/p>\n<p>The error message issue is related to the question of &#8220;Well, why would anybody want to do that?&#8221;\u00a0\u00a0 The related question is &#8220;What would anybody do with this information if I gave it to\u00a0 them?&#8221;.\u00a0 The answer is similar.\u00a0 &#8220;I don&#8217;t know what they might do, but why not tell them anyway?\u00a0 Would it kill you?&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A friend called me to say that he could not play one of the YouTube videos on my blog.\u00a0 It would play for a few seconds and then he would get a message &#8220;An error occurred&#8221;.\u00a0 Along with the error message there were all sorts of suggestions as to what he could do to fix [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[166],"tags":[],"class_list":{"0":"post-16895","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-stevegsposts","7":"czr-hentry"},"_links":{"self":[{"href":"https:\/\/ssgreenberg.name\/PoliticsBlog\/wp-json\/wp\/v2\/posts\/16895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ssgreenberg.name\/PoliticsBlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ssgreenberg.name\/PoliticsBlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ssgreenberg.name\/PoliticsBlog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ssgreenberg.name\/PoliticsBlog\/wp-json\/wp\/v2\/comments?post=16895"}],"version-history":[{"count":7,"href":"https:\/\/ssgreenberg.name\/PoliticsBlog\/wp-json\/wp\/v2\/posts\/16895\/revisions"}],"predecessor-version":[{"id":16902,"href":"https:\/\/ssgreenberg.name\/PoliticsBlog\/wp-json\/wp\/v2\/posts\/16895\/revisions\/16902"}],"wp:attachment":[{"href":"https:\/\/ssgreenberg.name\/PoliticsBlog\/wp-json\/wp\/v2\/media?parent=16895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ssgreenberg.name\/PoliticsBlog\/wp-json\/wp\/v2\/categories?post=16895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ssgreenberg.name\/PoliticsBlog\/wp-json\/wp\/v2\/tags?post=16895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}