From f1bab136d07a6d50901ee7aa5d7d2267ccb855fb Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Tue, 23 Dec 2014 14:21:04 -0800 Subject: [PATCH] Throw a caught error in the default warning module This throws an error that is immediately caught. This allows you to use the debugger's "break on caught exception" feature to break on warnings. This should help with tracking down these warnings using the stack. However, it could also add more noise to other debugging pattern. --- src/vendor/core/warning.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/vendor/core/warning.js b/src/vendor/core/warning.js index 5321055edb..9a2bec313d 100644 --- a/src/vendor/core/warning.js +++ b/src/vendor/core/warning.js @@ -33,7 +33,14 @@ if (__DEV__) { if (!condition) { var argIndex = 0; - console.warn('Warning: ' + format.replace(/%s/g, () => args[argIndex++])); + var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]); + console.warn(message); + try { + // --- Welcome to debugging React --- + // This error was thrown as a convenience so that you can use this stack + // to find the callsite that caused this warning to fire. + throw new Error(message); + } catch(x) {} } }; }