{"id":2621,"date":"2018-10-24T08:43:31","date_gmt":"2018-10-24T07:43:31","guid":{"rendered":"http:\/\/www.robertprice.co.uk\/robblog\/?p=2621"},"modified":"2018-11-04T00:21:51","modified_gmt":"2018-11-04T00:21:51","slug":"debugging-a-mendix-widget","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/","title":{"rendered":"Debugging a Mendix widget"},"content":{"rendered":"<p>I had to debug a <a href=\"https:\/\/docs.mendix.com\/howto\/custom-widget-development\/\">custom Mendix widget<\/a> that was failing. All that was shown on screen in red was &#8220;Could not create widget BHCCDropZone.widget.BHCCDropZone&#8221;.<\/p>\n<p>We&#8217;d recently upgraded to Mendix 7.18.1, so something looked like it happened during the upgrade.<\/p>\n<p>The first step was to make sure the appropriate access rights to the entity the widget uses were right. In this case they were.<\/p>\n<p>Next was to up the log levels from INFO to DEBUG in the Mendix Modeller to see if that gave me any clues. I could see the widget&#8217;s <code>constructor<\/code> and <code>postCreate<\/code> being run as I had <code>logger.debug<\/code> calls in those functions being run. However, one of my debug calls was not being reached, so I had narrowed down the location of problem.<\/p>\n<p>After this I added JavaScript breakpoints in the failing method using Chrome&#8217;s developer tools. The widget is only loaded the first time the page is reached. When I reached this page I singled stepped through, and found an exception being thrown by the JavaScript but being caught by Mendix. My error was&#8230;<\/p>\n<pre>\"TypeError: Converting circular structure to JSON\r\n    at JSON.stringify (<anonymous>)\r\n    at http:\/\/localhost:8080\/mxclientsystem\/mxui\/mxui.js?636758982080189581:74:164930\r\n    at Array.map (<anonymous>)\r\n    at t.log (http:\/\/localhost:8080\/mxclientsystem\/mxui\/mxui.js?636758982080189581:74:164840)\r\n    at http:\/\/localhost:8080\/mxclientsystem\/mxui\/mxui.js?636758982080189581:74:196250\r\n    at http:\/\/localhost:8080\/mxclientsystem\/mxui\/mxui.js?636758982080189581:74:166406\r\n    at Array.forEach (<anonymous>)\r\n    at t.log (http:\/\/localhost:8080\/mxclientsystem\/mxui\/mxui.js?636758982080189581:74:166377)\r\n    at t.debug (http:\/\/localhost:8080\/mxclientsystem\/mxui\/mxui.js?636758982080189581:74:165718)\r\n    at Object.postCreate (http:\/\/localhost:8080\/widgets\/BHCCDropZone\/widget\/BHCCDropZone.js?636758982080189581:80:11)\"\r\n<\/pre>\n<p>I could now see I had a circular data structure. <\/p>\n<p>Working backwards through the stack trace, I could see the problem was in my widget&#8217;s <code>postCreate<\/code> function, and it was a <code>debug<\/code> function causing the problem. This was the faulty code causing the widget to fail.<\/p>\n<p>My <code>postCreate<\/code> function looked like this&#8230;<\/p>\n<pre>postCreate: function () {\r\n  console.log(\"BHCCDropZone session\", mx.session);\r\n  logger.debug(this.id + \".postCreate\");\r\n  this.initBHCCDropZone();\r\n  logger.debug(\"this\", this);\r\n},\r\n<\/pre>\n<p>The faulty line was this&#8230;<\/p>\n<p><code>logger.debug(\"this\", this);<\/code><\/p>\n<p>Trying to send the contents of <code>this<\/code> to the debug logs was causing problems as it was a circular data structure. Removing this line of JavaScript fixed the problem, and the widget started to work again as expected.<\/p>\n<p>I hope this helps others in future when debugging &#8220;Could not create widget&#8221; errors in Mendix.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had to debug a custom Mendix widget that was failing. All that was shown on screen in red was &#8220;Could not create widget BHCCDropZone.widget.BHCCDropZone&#8221;. We&#8217;d recently upgraded to Mendix 7.18.1, so something looked like it happened during the upgrade. The first step was to make sure the appropriate access rights to the entity the &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Debugging a Mendix widget&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[98],"class_list":["post-2621","post","type-post","status-publish","format-standard","hentry","category-dev","tag-mendix"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Debugging a Mendix widget - Robert Price<\/title>\n<meta name=\"description\" content=\"How to debug &quot;Could not create widget&quot; errors in Mendix.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Debugging a Mendix widget - Robert Price\" \/>\n<meta property=\"og:description\" content=\"How to debug &quot;Could not create widget&quot; errors in Mendix.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-24T07:43:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-11-04T00:21:51+00:00\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/debugging-a-mendix-widget\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/debugging-a-mendix-widget\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Debugging a Mendix widget\",\"datePublished\":\"2018-10-24T07:43:31+00:00\",\"dateModified\":\"2018-11-04T00:21:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/debugging-a-mendix-widget\\\/\"},\"wordCount\":291,\"keywords\":[\"Mendix\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/debugging-a-mendix-widget\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/debugging-a-mendix-widget\\\/\",\"name\":\"Debugging a Mendix widget - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"datePublished\":\"2018-10-24T07:43:31+00:00\",\"dateModified\":\"2018-11-04T00:21:51+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"description\":\"How to debug \\\"Could not create widget\\\" errors in Mendix.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/debugging-a-mendix-widget\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/debugging-a-mendix-widget\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/debugging-a-mendix-widget\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Debugging a Mendix widget\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Debugging a Mendix widget - Robert Price","description":"How to debug \"Could not create widget\" errors in Mendix.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/","og_locale":"en_GB","og_type":"article","og_title":"Debugging a Mendix widget - Robert Price","og_description":"How to debug \"Could not create widget\" errors in Mendix.","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/","og_site_name":"Robert Price","article_published_time":"2018-10-24T07:43:31+00:00","article_modified_time":"2018-11-04T00:21:51+00:00","author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Debugging a Mendix widget","datePublished":"2018-10-24T07:43:31+00:00","dateModified":"2018-11-04T00:21:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/"},"wordCount":291,"keywords":["Mendix"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/","name":"Debugging a Mendix widget - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"datePublished":"2018-10-24T07:43:31+00:00","dateModified":"2018-11-04T00:21:51+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"description":"How to debug \"Could not create widget\" errors in Mendix.","breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/debugging-a-mendix-widget\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Debugging a Mendix widget"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/2621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=2621"}],"version-history":[{"count":2,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/2621\/revisions"}],"predecessor-version":[{"id":2623,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/2621\/revisions\/2623"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=2621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=2621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=2621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}