[SalesForce] $A.getCallback throws an error in lightning component

When i add the below line of code to a controller in a lightning component I get a Javascript error saying.

    var input = {
        callback : $A.getCallback(function(result) {
            alert(JSON.stringify(result));
        }); 
    };

Uncaught Error in $A.getCallback() [Cannot read property 'apply' of
undefined] throws at
http://adarshakb2.lightning.localhost.force.com:6109/l/%7B%22mode%22%3A%22DEV%22%2C%22app%22%3A%22one%3Aone%22%2C%22fwuid%22%3A%22upZaWQWEemyWxA8BDbVXtg%22%2C%22loaded%22%3A%7B%22APPLICATION%40markup%3A%2F%2Fone%3Aone%22%3A%22Hdm40jpREpk5B2bFA5qAdg%22%7D%2C%22requestedLocales%22%3A%5B%22en_US%22%2C%22en%22%5D%2C%22ls%22%3A%22YN%22%7D/app.js:86682:21
at value (http://adarshakb2.lightning.localhost.force.com:6109/auraFW/javascript/upZaWQWEemyWxA8BDbVXtg/aura_dev.js:16166:18)
at Object.create (http://adarshakb2.lightning.localhost.force.com:6109/auraFW/javascript/upZaWQWEemyWxA8BDbVXtg/aura_dev.js:16277:66)
at Object.$createForDef$ (http://adarshakb2.lightning.localhost.force.com:6109/auraFW/javascript/upZaWQWEemyWxA8BDbVXtg/aura_dev.js:16255:17)
at eval (eval at (http://adarshakb2.lightning.localhost.force.com:6109/auraFW/javascript/upZaWQWEemyWxA8BDbVXtg/aura_dev.js:1441:10),
:4:97)
at ComponentClassRegistry.$getComponentClass$ (http://adarshakb2.lightning.localhost.force.com:6109/auraFW/javascript/upZaWQWEemyWxA8BDbVXtg/aura_dev.js:3907:33)
at AuraComponentService.$getComponentClass$ (http://adarshakb2.lightning.localhost.force.com:6109/auraFW/javascript/upZaWQWEemyWxA8BDbVXtg/aura_dev.js:10907:40)
at AuraComponentService.$createComponentPriv$ (http://adarshakb2.lightning.localhost.force.com:6109/auraFW/javascript/upZaWQWEemyWxA8BDbVXtg/aura_dev.js:11397:33)
at aura$component.Component.$createComponentStack$ (http://adarshakb2.lightning.localhost.force.com:6109/auraFW/javascript/upZaWQWEemyWxA8BDbVXtg/aura_dev.js:5284:49)
at aura$component.Component.$setupAttributes$ (http://adarshakb2.lightning.localhost.force.com:6109/auraFW/javascript/upZaWQWEemyWxA8BDbVXtg/aura_dev.js:5421:29)
at aura$component.Component (http://adarshakb2.lightning.localhost.force.com:6109/auraFW/javascript/upZaWQWEemyWxA8BDbVXtg/aura_dev.js:4261:8)

What is wrong? I have wrapped the callback as suggested in https://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_lightning_get_callback.htm.

I am using locker service to display this component in lightning app.

Best Answer

I ran into something similar while debugging on of my open source projects, aura-ng, under LS today and it turned out that Aura Framework's error reporting is actually showing you a useless cascaded error that is masking the real problem that most likely has a nice meaningful error message. Open up developer tools in the browser and configure it to break on all errors (break on handled exceptions) and I bet you will see the real issue displayed in the error popup. Btw the actual error raised by LS in my code was 100% legitimate - I was using an undocumented/unsupported Aura APIs in my code! I was also using the reserved keyword "arguments" as a variable name (not valid in strict mode JavaScript).