{"id":102650,"date":"2019-07-04T07:00:00","date_gmt":"2019-07-04T14:00:00","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/oldnewthing\/?p=102650"},"modified":"2019-07-03T22:12:49","modified_gmt":"2019-07-04T05:12:49","slug":"20190704-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20190704-00\/?p=102650","title":{"rendered":"Generating good error messages from code analysis tools is harder than it looks"},"content":{"rendered":"<p>I was writing a tool to analyze Windows Runtime winmd files, and the tool had to generate error messages when it discovered something that violated our team&#8217;s internal rules.<\/p>\n<p>It turns out that generating good error messages from code analysis tools is hard. My tool detected, for example, that the name of a method parameter was improperly changed. (Method parameter names are used by some language projections, so <a href=\"https:\/\/github.com\/Microsoft\/Windows-universal-samples\/releases\/tag\/v3.0.5\"> changing the name of the parameter is a breaking change<\/a>.)<\/p>\n<p>It was hard enough detecting that a change occurred that violated our team&#8217;s internal rules. Now came the problem of reporting it.<\/p>\n<p>My original code returned a Boolean value that said whether everything was okay, but it&#8217;s obviously a bad idea for the tool to simply say &#8220;Sorry, you made a mistake. Now go fix it.&#8221; I had to modify my code to report enough information in order to diagnose the problem and fix it. This means that instead of just &#8220;Sorry, you made a mistake,&#8221; the error message was something like &#8220;Disallowed change of parameter name from &#8216;index&#8217; to &#8216;i&#8217; in parameter 1 of method GetAt of interface IVector (with T = string) implemented by class MyVector in file Sample.winmd, compared to Baseline.winmd.&#8221;<\/p>\n<p>I developed an appreciation for how hard it is to generate good error messages, especially if the thing you&#8217;re reporting is not something that a human being wrote directly, which means that you can&#8217;t use line numbers as reference points.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Describing the problem accurately, with enough diagnostics to chase the problem <\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-102650","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Describing the problem accurately, with enough diagnostics to chase the problem <\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/102650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=102650"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/102650\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=102650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=102650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=102650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}