Skip to content

Commit 48327cd

Browse files
committed
jQuery.Deferred.getErrorHook: Create the page
Also, create a page for the now deprecated `jQuery.Deferred.getStackHook` and update the `jQuery.readyException` docs to mention the async error. Fixes gh-1221
1 parent ebb139a commit 48327cd

4 files changed

+68
-4
lines changed

categories.xml

+6
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@
108108
<p>For more information, see the Release Notes/Changelog at <a href="https://blog.jquery.com/2020/04/10/jquery-3-5-0-released/">https://blog.jquery.com/2020/04/10/jquery-3-5-0-released/</a></p>
109109
]]></desc>
110110
</category>
111+
<category name="Deprecated 3.7" slug="deprecated-3.7">
112+
<desc><![CDATA[
113+
<p>All the aspects of the API that were deprecated in the corresponding version of jQuery.</p>
114+
<p>For more information, see the Release Notes/Changelog at <a href="https://blog.jquery.com/2023/05/11/jquery-3-7-0-released-staying-in-order/">https://blog.jquery.com/2023/05/11/jquery-3-7-0-released-staying-in-order/</a></p>
115+
]]></desc>
116+
</category>
111117
</category>
112118
<category name="Dimensions" slug="dimensions">
113119
<desc><![CDATA[These methods are used to get and set the CSS dimensions for the various properties.]]></desc>
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<entry type="method" name="jQuery.Deferred.getErrorHook" return="Error">
3+
<title>jQuery.Deferred.getErrorHook()</title>
4+
<signature>
5+
<added>3.7</added>
6+
</signature>
7+
<desc>Return an Error instance with a defined stack.</desc>
8+
<longdesc>
9+
<div class="warning">
10+
<p>Note: This API is not defined by default. It may be provided by the user and jQuery will then use it internally.</p>
11+
</div>
12+
<p>When <code>jQuery.Deferred.getErrorHook</code> is defined, it extends the <code>jQuery.Deferred</code> features added in jQuery 3.0 to include an error captured before the async barrier whenever a Deferred throws an exception. This makes it easier to find programming errors that occur inside Deferreds. You can find an example implementation you can copy-paster below, or you can use <a href="https://github.com/dmethvin/jquery-deferred-reporter">jquery-deferred-reporter</a> plugin.</p>
13+
<pre><code>
14+
jQuery.Deferred.getErrorHook = function() {
15+
try {
16+
throw new Error( "Exception in jQuery.Deferred" );
17+
} catch ( err ) {
18+
return err;
19+
}
20+
};
21+
</code></pre>
22+
<h4>Why does this API exist?</h4>
23+
<p>Prior to jQuery 3.0, Deferreds would simply terminate and the browser would generate a message on the console if an exception occurred such as attempting to call an undefined method as a function (e.g., <code>myobject.missingFunction()</code>). As of version 3.0, <code>jQuery.Deferred</code> follows the Promise/A+ specification when you use the <code>.then</code> method. The spec requires all errors to be trapped by the Promise, which prevents console errors from being logged. If the user has forgotten to add a handler for rejected promises, this can result in the error being silently swallowed with no notification at all!</p>
24+
<p>The native <code>Promise</code> object as implemented in the browser tracks Promise rejections and reports problems on the console. However, doing the same type of reporting in the JavaScript world is much more difficult. jQuery itself is unable to use the native Promise because jQuery.Deferred implements a superset of Promise that requires additional features for methods like <code>.done</code> or <code>.fail</code>, and because Promise is not implemented on all the platforms that jQuery supports.</p>
25+
</longdesc>
26+
<category slug="deferred-object"/>
27+
<category slug="version/3.7"/>
28+
</entry>
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<entry type="method" name="jQuery.Deferred.getStackHook" return="Error" deprecated="3.7" removed="4.0">
3+
<title>jQuery.Deferred.getStackHook()</title>
4+
<signature>
5+
<added>3.0</added>
6+
</signature>
7+
<desc>Return an Error instance with a defined stack.</desc>
8+
<longdesc>
9+
<div class="warning">
10+
<p>Note: This API has been deprecated in jQuery 3.7; please use the <a href="/jQuery.Deferred.getErrorHook/"><code>jQuery.Deferred.getErrorHook</code></a> method instead.</p>
11+
</div>
12+
<div class="warning">
13+
<p>Note: This API is not defined by default. It may be provided by the user and jQuery will then use it internally.</p>
14+
</div>
15+
<p>See <a href="/jQuery.Deferred.getErrorHook/"><code>jQuery.Deferred.getErrorHook</code></a> for the context why this API was created. Initially, we advised users to assign to it a function returning an error stack:</p>
16+
<pre><code>
17+
jQuery.Deferred.getStackHook = function() {
18+
try {
19+
throw new Error( "Exception in jQuery.Deferred" );
20+
} catch ( err ) {
21+
return err.stack; // stack property returned here
22+
}
23+
};
24+
</code></pre>
25+
<p>However, when such a stack is then logged by jQuery from inside of <a href="/jQuery.Deferred.exceptionHook/"><code>jQuery.Deferred.exceptionHook</code></a>, the browser won't apply source maps. Therefore, we changed the recommendation to return the full error object itself. To make it clearer, the API was also renamed.</p>
26+
</longdesc>
27+
<category slug="deferred-object"/>
28+
<category slug="version/3.0"/>
29+
<category slug="deprecated/deprecated-3.7"/>
30+
</entry>

entries/jQuery.readyException.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
</argument>
1010
</signature>
1111
<longdesc>
12-
<p>This method is fired when an error is thrown synchronously in a function wrapped in <code>jQuery()</code> or <code>jQuery( document ).ready()</code>, or equivalent. By default it re-throws the error in a timeout so that it's logged in the console and passed to <code>window.onerror</code> instead of being swallowed. Overwrite this method if you want to handle such errors differently.</p>
12+
<p>This method is fired when an error is thrown synchronously in a function wrapped in <code>jQuery()</code> or <code>jQuery( document ).ready()</code>, or equivalent. By default, it re-throws the error in a timeout so that it's logged in the console and passed to <code>window.onerror</code> instead of being swallowed. Overwrite this method if you want to handle such errors differently.</p>
1313
</longdesc>
1414
<example>
15-
<desc>Pass the received error to <code>console.error</code>.</desc>
15+
<desc>Pass the received errors to <code>console.error</code>. The second parameter is defined if <a href="/jQuery.Deferred.getErrorHook/"><code>jQuery.Deferred.getErrorHook</code></a> is defined.</desc>
1616
<code><![CDATA[
17-
jQuery.readyException = function( error ) {
18-
console.error( error );
17+
jQuery.readyException = function( error, asyncError ) {
18+
console.error( error, asyncError );
1919
};
2020
]]></code>
2121
</example>

0 commit comments

Comments
 (0)