Dojo.config.deferred Error
Contents |
frustrating chore. To compound the already difficult task of debugging, browser vendors each have their own style of error messaging, some of which are confusing, cryptic,
Dojo Deferred Example
or downright misleading to the untrained eye. Through the delivery of our Dojo dojo promise all workshops, we've observed a number of common mistakes that are easy to fix once you decipher the error message.
Dojo When
Take some time to familiarize yourself with the following common errors that appear when working with Dojo, their symptoms, and their solutions. With this knowledge, writing manageable code is not only dojo/promise/promise possible, but a lot less cryptic. Issue: Missing Parameter What you're likely to see in your debugging environment Firefox + Firebug ReferenceError: on is not defined Chrome Uncaught ReferenceError: on is not defined Internet Explorer 9 The value of the property ‘on' is null or undefined, not a Function object Possible Cause You are missing a module parameter in the callback function dojo require is not defined of require. As you can see in the example, we list dojo/on as a dependency, but forget to specify it as a parameter to our callback function. As such, whenever we attempt to reference it, it fails because it is undefined. require(["dojo/dom", "dojo/on"], function (dom) { on(dom.byId("button"), "click", function (e) { console.log("My button was clicked!"); }); }); Solution Ensure you specify a callback parameter for each module that you're including to which you will need locally scoped access. If you're getting a ReferenceError or "not a Function", chances are, you missed a parameter. Issue: Callback Parameter Mismatch What you're likely to see in your debugging environment Firefox + Firebug TypeError: dom.byId is not a function Chrome Uncaught TypeError: Object function has no method ‘byId' Internet Explorer 9 Object doesn't support property or method ‘byId' Possible Cause The callback parameter order does not match the dependency order. As you can see in the code, we require our dependencies in the order of dojo/dom and then dojo/on; however, in our callback, we have them in the order of dojo/on and then dojo/dom. Dojo does not magically know t
emitted to error console Reported by: asudoh Owned by: dylan Priority: undecided Milestone: 1.13 Component: Core Version: 1.8.0 Keywords: Cc: Blocked by: Blocking: Description In 1.7 version of dojo/_base/Deferred.js, there is code not
Uncaught Referenceerror Dojo Is Not Defined
to emit CancelError: if(!error || error.log !== false){ (dojo.config.deferredOnError || function(x){ console.error(x); dojo error multipledefine })(error); } However, it's gone in 1.8, even in back-compat dojo/_base/Deferred.js, like: if(has("config-useDeferredInstrumentation")){ if(NewDeferred.instrumentRejected){ NewDeferred.instrumentRejected(error, !!nextListener); } }
Dojo Cannot Read Property 'on' Of Undefined
Cannot see the code not to emit CancelError in instrumentation code, either. Attached a test case and a patch. Attachments (2) testDeferred.html (644 bytes) - added by asudoh 4 https://www.sitepen.com/blog/2012/10/31/debugging-dojo-common-error-messages/ years ago. Test case, /dojo-1.8 portion of this file should be replaced with the correct path of Dojo Toolkit (1.7 or 1.8) instrumentation.js.diff (444 bytes) - added by asudoh 4 years ago. A patch Download all attachments as: .zip Oldest first Newest first Threaded Comments only Change History (12) Changed 4 years ago by asudoh Attachment testDeferred.html added Test case, https://bugs.dojotoolkit.org/ticket/16547 /dojo-1.8 portion of this file should be replaced with the correct path of Dojo Toolkit (1.7 or 1.8) Changed 4 years ago by asudoh Attachment instrumentation.js.diff added A patch comment:1 Changed 4 years ago by bill Component changed from General to Core Owner set to markwubben Status changed from new to assigned Summary changed from CancelError emitted to error console to [patch] [cla] CancelError emitted to error console comment:2 Changed 4 years ago by markwubben Seems sensible, though dojo/Deferred doesn't set .log = false on cancelation errors, so those would still be reported. Error reporting in Dojo's promise implementation is underdeveloped, although there are some suggestions in <https://github.com/promises-aplus/unhandled-rejections-spec/issues?sort=updated&state=open> that would improve matters. Even with those changes though I'm not sure whether cancel errors should be suppressed. Bill, thoughts? comment:3 Changed 4 years ago by bill Most (or all?) of the time, cancel "errors" aren't actually errors. For example, when FilteringSelect sends and XHR to the server but then the user types more characters before the XHR completes, it cancels the original XHR and sends a new one.
The Dojo Loader Introduction dojo.js Configuration/Feature Detection The AMD API Module Identifiers Generic Script Injection Alias Modules Map Config Normalizing Module https://dojotoolkit.org/reference-guide/1.8/loader/amd.html Identifiers Relocating Module Namespaces Utility Functions CommonJS require, exports, and module Plugins Window Load Detection The Micro Event API Error Reporting Debugging Tracing Non-browser Environments The Legacy API http://stackoverflow.com/questions/9183159/how-do-i-debug-my-asynchronous-promise-based-code-if-the-library-is-swallowing Modes of Operation Configuration Reference Introduction¶ The Dojo loader includes two APIs: The Asynchronous Module Definition (AMD) API ("AMD API") The legacy dojo API which consists of dojo.require(), dojo.provide(), dojo.requireIf(), dojo.requireAfterIf(), dojo.platformRequire(), and dojo.requireLocalization() ("legacy loader API") The AMD API is new for Dojo 1.7. It is the same API implemented by RequireJS, curl, and bdLoad (the dojo implementation is an adoption of bdLoad). This exciting new standard for writing and loading modules dramatically improves code portability and is not defined interoperability. Equally important, it allows modules to be loaded asynchronously, which provides two key benefits versus the old synchronous API: Modules can be downloaded asynchronously and concurrently, thereby decreasing page load times up to 10x. Hacks such as debugAtAllCosts are no longer needed in order to provide informative debugging (e.g. stack traces) in all browsers. While each loader offers a different set of extra features, the core API of all of these loaders is compatible and most of the tutorial material for any one loader is applicable to the others. In addition to the core loader APIs, the new Dojo loader includes several other useful features: Multiple platform support: By default, the Dojo loader includes configurations for the browser, node.js, and Rhino. Environment-specific configuration files are typically less than 100 lines of code and can be easily written to extend Dojo support to other JavaScript environments (see Non-browser Environments). has.js API: The Dojo loader implements the has.js API, and uses that API to bracket several l
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How do I debug my asynchronous, promise based code if the library is swallowing all the exceptions? up vote 13 down vote favorite 3 The Problem JSFiddle: http://jsfiddle.net/missingno/Gz8Pe/2/ I have some code that looks like this: var d = new Deferred(); d.resolve(17); return d.then(function(){ //do some stuff... }) .then(function(){ var obj = a_funtion_that_returns_null_on_IE(); var x = obj.some_property; //BOOM! }); The problem is that when I am on IE all I can see are 'obj' is null or not an object errors, without any reference to the corresponding line number and without the debugger halting at the offending line (like I wish it would). This kind of issue is making the code a pain to debug and the only solutions I can think of right now (messing around with the control flow library or resorting to step-by-step debugging with the debugger or console.log) are things I would rather not have to do. What I think is going on In order to allow errbacks to be added after the chain is fired, then will preemptively catch any exceptions thrown by the callbacks. I think this is the reason for the IE debugger not halting on the error or showing the usual error message witht the line number in it. The error messages without the line numbers are coming from the control-flow library: it provides a deferredOnError hook that is called whenever an exception is caught and saved for later and the default behaviour is console.error-ing the Error object: dojo.config.deferredOnError = function(err){ //a chance to log the exception after it is captured by "then" //or do other things with it console.error(err); } Sadly, I could not figure out a way to get the line number or stack trace from the error object in IE and the hook is called in a way that does not allow me