Opened 9 years ago

Closed 7 years ago

#12222 closed defect (invalid)

Error in one dojo.ready() or dojo.addOnLoad() will break all following calls

Reported by: georgecalm Owned by: Rawld Gill
Priority: low Milestone: 1.8
Component: Core Version: 1.5
Keywords: ready addOnLoad dojo.ready dojo.addOnLoad Cc:
Blocked By: Blocking:

Description

Issue:

When an error is thrown inside one dojo.ready() [or dojo.addOnLoad()], the callback-functions in the following dojo.ready() will not be called.

Example:

dojo.ready(function(){console.log("one");})
one
undefined

dojo.ready(function(){console.log("two"); throw new Error("err"); })
two
Error: err

dojo.ready(function(){console.log("three");})
undefined

Note: "three" will never be written to the console.

Change History (5)

comment:1 Changed 8 years ago by Chris Mitchell

Owner: anonymous deleted

comment:2 Changed 8 years ago by Adam Peller

this is a dup of a ticket I wrote and there was a long discussion on it... need to find this ticket...

comment:3 Changed 8 years ago by Colin Snover

Priority: highblocker

Bulk update of open ticket priorities.

comment:4 Changed 7 years ago by bill

Component: GeneralCore
Owner: set to Rawld Gill
Status: newassigned

comment:5 Changed 7 years ago by Rawld Gill

Milestone: tbd1.8
Priority: blockerlow
Resolution: invalid
Status: assignedclosed

We experimented with a version of dojo.ready that swallowed errors silently. This idea was rejected in [26408]. Indeed, it's probably irrational to muddle along after an error as if the error didn't happen.

Also, the soln is simple: if you've got a ready function that might throw and you don't care about throwing, then protect that function with a try-catch.

Lastly, dojo.ready can be nudged to start firing again after an error by adding another dojo.ready callback. Here is an example you can set async to either truthy or falsey...it works both ways.

<html>
<head>
    <title>Nudge Dojo Ready After an Error</title>
	<script src="dojo/dojo.js" data-dojo-config="async:0"></script>
	<script>
		require(["dojo"], function(dojo){
			dojo.ready(function(){console.log("one");})
			dojo.ready(function(){console.log("two"); throw new Error("err"); })
			dojo.ready(function(){console.log("three");})
			require(["dojo/domReady"], function(){
				setTimeout(function(){
					console.log("nudging the ready machinery");
					dojo.ready(function(){console.log("nudge complete")});
				}, 200);
			});
		});
	</script>
</head>
<body>
</body>
</html>
Note: See TracTickets for help on using tickets.