From 801325bb38da5ece981af75da441b37a45cfa886 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Wed, 9 Mar 2016 11:29:47 -0800 Subject: [PATCH] fix(deprecate-utils): Add location where deprecation warning was issued - Resolves #1599 --- src/deprecate-utils.coffee | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/deprecate-utils.coffee b/src/deprecate-utils.coffee index 4200b53b0..165209a0e 100644 --- a/src/deprecate-utils.coffee +++ b/src/deprecate-utils.coffee @@ -1,6 +1,16 @@ _ = require 'underscore' class DeprecateUtils + # See + # http://www.codeovertones.com/2011/08/how-to-print-stack-trace-anywhere-in.html + @parseStack: (stackString) -> + stack = stackString + .replace(/^[^\(]+?[\n$]/gm, '') + .replace(/^\s+at\s+/gm, '') + .replace(/^Object.\s*\(/gm, '{anonymous}()@') + .split('\n') + return stack + @warn: (condition, message) -> console.warn message if condition @@ -8,10 +18,11 @@ class DeprecateUtils if NylasEnv.inDevMode() and not NylasEnv.inSpecMode() warn = true newFn = => + stack = DeprecateUtils.parseStack((new Error()).stack) DeprecateUtils.warn( warn, "Deprecation warning! #{fnName} is deprecated and will be removed soon. - Use #{newName} instead." + Use #{newName} instead.\nCheck your code at #{stack[1]}" ) warn = false return fn.apply(ctx, arguments)