Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot set property 'impl' of null #344

Closed
johnnywang opened this issue Jul 27, 2017 · 22 comments
Closed

Uncaught TypeError: Cannot set property 'impl' of null #344

johnnywang opened this issue Jul 27, 2017 · 22 comments
Labels
Milestone

Comments

@johnnywang
Copy link

I'm not sure what the exact repro conditions for this error is, as it didn't seem to be breaking consistently everywhere our code was used. We had previously been using an older version of the JS Rollbar snippet:

var _rollbarConfig = {
    accessToken: "<%=ROLLBAR_ACCESS_TOKEN%>",
    captureUncaught: false,
    payload: {
        environment: "<%=ENVIRONMENT%>"
    }
};
!function(a,b){function c(b){this.shimId=++h,this.notifier=null,this.parentShim=b,window.logger=function(){},a.console&&void 0===a.console.shimId&&(window.logger=a.console.log)}function d(b,c,d){!d[4]&&a._rollbarWrappedError&&(d[4]=a._rollbarWrappedError,a._rollbarWrappedError=null),b.uncaughtError.apply(b,d),c&&c.apply(a,d)}function e(b){var d=c;return g(function(){if(this.notifier)return this.notifier[b].apply(this.notifier,arguments);var c=this,e="scope"===b;e&&(c=new d(this));var f=Array.prototype.slice.call(arguments,0),g={shim:c,method:b,args:f,ts:new Date};return a._rollbarShimQueue.push(g),e?c:void 0})}function f(a,b){if(b.hasOwnProperty&&b.hasOwnProperty("addEventListener")){var c=b.addEventListener;b.addEventListener=function(b,d,e){c.call(this,b,a.wrap(d),e)};var d=b.removeEventListener;b.removeEventListener=function(a,b,c){d.call(this,a,b&&b._wrapped?b._wrapped:b,c)}}}function g(a,b){return b=b||window.logger,function(){try{return a.apply(this,arguments)}catch(c){b("Rollbar internal error:",c)}}}var h=0;c.init=function(a,b){var e=b.globalAlias||"Rollbar";if("object"==typeof a[e])return a[e];a._rollbarShimQueue=[],a._rollbarWrappedError=null,b=b||{};var h=new c;return g(function(){if(h.configure(b),b.captureUncaught){var c=a.onerror;a.onerror=function(){var a=Array.prototype.slice.call(arguments,0);d(h,c,a)};var g,i,j=["EventTarget","Window","Node","ApplicationCache","AudioTrackList","ChannelMergerNode","CryptoOperation","EventSource","FileReader","HTMLUnknownElement","IDBDatabase","IDBRequest","IDBTransaction","KeyOperation","MediaController","MessagePort","ModalWindow","Notification","SVGElementInstance","Screen","TextTrack","TextTrackCue","TextTrackList","WebSocket","WebSocketWorker","Worker","XMLHttpRequest","XMLHttpRequestEventTarget","XMLHttpRequestUpload"];for(g=0;g<j.length;++g)i=j[g],a[i]&&a[i].prototype&&f(h,a[i].prototype)}return a[e]=h,h},h.logger)()},c.prototype.loadFull=function(a,b,c,d){var e=g(function(){var a=b.createElement("script"),e=b.getElementsByTagName("script")[0];a.src=d.rollbarJsUrl,a.async=!c,a.onload=f,e.parentNode.insertBefore(a,e)},window.logger),f=g(function(){if(void 0===a._rollbarPayloadQueue)for(var b,c,d,e,f=new Error("rollbar.js did not load");b=a._rollbarShimQueue.shift();)for(d=b.args,e=0;e<d.length;++e)if(c=d[e],"function"==typeof c){c(f);break}},window.logger);g(function(){c?e():a.addEventListener?a.addEventListener("load",e,!1):a.attachEvent("onload",e)},window.logger)()},c.prototype.wrap=function(b){try{if("function"!=typeof b)return b;if(b._isWrap)return b;if(!b._wrapped){b._wrapped=function(){try{return b.apply(this,arguments)}catch(c){throw a._rollbarWrappedError=c,c}},b._wrapped._isWrap=!0;for(var c in b)b.hasOwnProperty(c)&&(b._wrapped[c]=b[c])}return b._wrapped}catch(d){return b}};for(var i="log,debug,info,warn,warning,error,critical,global,configure,scope,uncaughtError".split(","),j=0;j<i.length;++j)c.prototype[i[j]]=e(i[j]);var k="//d37gvrvc0wt4s1.cloudfront.net/js/v1.1/rollbar.min.js";_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||k;var l=c.init(a,_rollbarConfig);l.loadFull(a,b,!1,_rollbarConfig)}(window,document);

which was throwing the error referenced in #98. And while we weren't double-loading Rollbar (in so far as rollbar.min.js was only ever requested once), as far as I could make out from the latest minified snippet on https://rollbar.com/docs/notifier/rollbar.js/, there now seem to be some NPE guards, so we tried updating to the latest, only to get reports of the error mentioned in the title.

@rokob
Copy link
Contributor

rokob commented Aug 3, 2017

This is odd, let me see if I can figure out what might cause this, I've never heard of it before.

@johnnywang
Copy link
Author

For reference, this was while using the v2.0.4 snippet

@johnnywang
Copy link
Author

Tried this again just now with v2.1.3 and ran into the same problem. Here's a copy of the reversed stack trace (so bottom up) I'm seeing, line by line, since it's been minified together with our code:

  1. I think this is internal code
    function t(r) {
        if (n[r])
            return n[r].exports;
        var o = n[r] = {
            exports: {},
            id: r,
            loaded: !1
        };
        return e[r].call(o.exports, o, o.exports, t), // <------- this line
        o.loaded = !0,
        o.exports
    }
  1. Pretty sure this is internal code
, function(e, t, n) {
    var r, o, i, a, s, u, c, A;
    n(68).polyfill(),
    n(67).polyfill(),
    n(79),
    n(80),
    s = n(47), // <------- this line
    A = n(3),
    i = n(9),
    u = n(55),
    r = n(61),
    u(),
    function t(r) {
        if (n[r])
            return n[r].exports;
        var o = n[r] = {
            exports: {},
            id: r,
            loaded: !1
        };
        return e[r].call(o.exports, o, o.exports, t), // <------- this line again
        o.loaded = !0,
        o.exports
    }
  1. Rollbar snippet
    }([function(e, t, n) {  // <------- this line
        var r = n(1)
          , o = n(4);
        s = s || {},
        s.rollbarJsUrl = s.rollbarJsUrl || "https://cdnjs.cloudflare.com/ajax/libs/rollbar.js/2.1.3/rollbar.min.js",
        s.async = void 0 === s.async || s.async;
        var i = r.setupShim(window, s)
          , a = o(s);
        window.rollbar = r.Rollbar,
        i.loadFull(window, document, !s.async, s, a)
    }
  1. Rollbar
    !function(e) {
        function t(r) {
            if (n[r])
                return n[r].exports;
            var o = n[r] = {
                exports: {},
                id: r,
                loaded: !1
            };
            return e[r].call(o.exports, o, o.exports, t),
            o.loaded = !0,
            o.exports
        }
        var n = {};
        return t.m = e,
        t.c = n,
        t.p = "",
        t(0)  // <------- this line
    }([function(e, t, n) {
  1. Rollbar
    !function(e) {
        function t(r) {
            if (n[r])
                return n[r].exports;
            var o = n[r] = {
                exports: {},
                id: r,
                loaded: !1
            };
            return e[r].call(o.exports, o, o.exports, t),  // <------- this line 
            o.loaded = !0,
            o.exports
        }
        var n = {};
        return t.m = e,
        t.c = n,
        t.p = "",
        t(0)
    }([function(e, t, n) {
  1. Rollbar
    }([function(e, t, n) {
        var r = n(1)
          , o = n(4);
        s = s || {},
        s.rollbarJsUrl = s.rollbarJsUrl || "https://cdnjs.cloudflare.com/ajax/libs/rollbar.js/2.1.3/rollbar.min.js",
        s.async = void 0 === s.async || s.async;
        var i = r.setupShim(window, s)  // <------- this line 
          , a = o(s);
        window.rollbar = r.Rollbar,
        i.loadFull(window, document, !s.async, s, a)
    }
  1. Rollbar
        function a(e, t) {
            var n = t.globalAlias || "Rollbar";
            if ("object" == o(e[n]))
                return e[n];
            e._rollbarShims = {},
            e._rollbarWrappedError = null;
            var i = new d(t);  // <------- this line 
            return r(function() {
                return t.captureUncaught && (i._rollbarOldOnError = e.onerror,
                u.captureUncaughtExceptions(e, i, !0),
                u.wrapGlobals(e, i, !0)),
                t.captureUnhandledRejections && u.captureUnhandledRejections(e, i, !0),
                e[n] = i,
                i
            })()
        }
  1. Internal
  function bind(context) {
    if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
    var __method = this, args = slice.call(arguments, 1);
    return function() {
      var a = merge(args, arguments);
      return __method.apply(context, a);  // <------- this line 
    }
  }
  1. Rollbar
        function n(e, t) {
            this.impl = e(t, this),  // <------- this line 
            this.options = t,
            r(n.prototype)
        }

@rokob
Copy link
Contributor

rokob commented Aug 22, 2017

I am a little confused, are you including the snippet in a javascript file with other code and then minifying the whole thing? That doesn't seem to really make a lot of sense with how the snippet is designed. You should probably just be importing the package and using a bundling system to handle the loading then.

@JasonSooter
Copy link

I have this issue as well:

I am receiving this error in the console with the rollbar script on our site. It's a Magento site. The error points column 5438 of line 234(the line of the rollbar script).

Support told me to leave a message here.

Our site is https://www.theorganicbloom.com.

Let me know if I can be of any assistance

@rivkahstandig3636 rivkahstandig3636 added this to the v2.3.4 milestone Dec 27, 2017
@rivkahstandig3636 rivkahstandig3636 modified the milestones: v2.3.9, v3.0.0, v2.4.0 Feb 28, 2018
@brainsqueezer
Copy link

Same here. Possible relation with Prototype 1.7 library. The stack trace says it calls that library but didn't had time to review it more deeply. Had to revert to Rollbar.js 1.8

@arollason
Copy link

arollason commented Apr 24, 2018

Is there any update to this issue?
Alternatively, @brainsqueezer could you provide the JavaScript snippet you are using to include version 1.8 of the rollbar library?

@rivkahstandig3636
Copy link
Contributor

This will be worked on for the next release, which should be within the next few weeks. Sorry for the delay!

@rivkahstandig3636 rivkahstandig3636 modified the milestones: v2.4.0, v2.4.1 May 17, 2018
@mlent
Copy link

mlent commented May 30, 2018

@rivkahstandig3636 Can you please share whether this has been released yet? We are eagerly waiting on a fix as this issue renders our error tracking useless! Thank you.

@rivkahstandig3636
Copy link
Contributor

@mlent It unfortunately got pushed back, but should be coming out with a release next Monday. I'm sorry about that!

@p-himik
Copy link

p-himik commented Jun 2, 2018

I'm not sure if it's related, but I keep getting Uncaught TypeError: Cannot read property 'info' of undefined errors when trying to use Rollbar.info with Rollbar 2.4.1. It appears to originate at https://github.com/rollbar/rollbar.js/blob/master/src/browser/rollbarWrapper.js#L11

@mlent
Copy link

mlent commented Jun 5, 2018

@rivkahstandig3636 Thanks for the update - it would be really helpful to know as soon as this is available, as our other errors are totally drowned out by this one. Thanks!

@JasonSooter
Copy link

Status update?

@rivkahstandig3636 rivkahstandig3636 modified the milestones: v2.4.1, v2.4.2 Jun 17, 2018
@rokob
Copy link
Contributor

rokob commented Jun 26, 2018

HUZZAH! Thank you @functionalStoic for giving me a live demo with the bug. It took me a while to track this down, but this is happening because Prototype is monkey patching bind: https://github.com/prototypejs/prototype/blob/1fb9728ed109cfd682225a13eda13acfb91a94dc/src/lang/function.js#L108,L115

WTF???

Suppose we do

var ClassTemplate = function(i, o) { this.i = i; this.o = o; this.name='hello'; }
var SpecificClass = ClassTemplate.bind(undefined, 42);
var myInstance = new SpecificClass({a: 42})

In a normal world you would observe this:

> myInstance
< SpecificClass {i: 42, o: {…}, name: "hello"}
> myInstance.i
< 42

If you include prototypejs:

> myInstance
< {}
> myInstance.i 
< undefined

The best fix is to stop using Prototypejs, that kind of global behaviour is troubling. However, I understand that might not be possible for a variety of reasons, let me see what I can do about a fix that works with Prototype now that I know what is going on.

@rokob
Copy link
Contributor

rokob commented Jun 26, 2018

Also if anyone is seeing this error and they are not including Prototype that would be good to know because that would mean there is something else going on. But I strongly suspect this is the culprit.

@mlent
Copy link

mlent commented Jun 29, 2018

@rokob thanks for getting to the bottom of this! can you please share how soon you expect this to be released? thanks!

@rokob
Copy link
Contributor

rokob commented Jun 29, 2018

I'm merging a bunch of stuff right now and will do a release later today.

@mlent
Copy link

mlent commented Jun 29, 2018

Thank you very much!

@JasonSooter
Copy link

@rokob I am still receiving the same error after having updated to the new 2.4.2. Any ideas. I changed the script tag to refer to the 2.4.2. Does the whole script need to change? Maybe something I did incorrectly? You can check www.theorganicbloom.com to see the error in the console.

I completely agree with not using PrototypeJS. That kind of global behavior is troubling indeed. Unfortunately, it is still built into Magento and extracting it would be quite challenging if not impossible.

Do I need to open a new issue about it as this one has been closed?

@rivkahstandig3636 rivkahstandig3636 modified the milestones: v2.4.2, v2.4.3 Jul 1, 2018
@rokob
Copy link
Contributor

rokob commented Jul 6, 2018

The entire snippet needs to change. For some updates the snippet does not change so you are safe just changing the version inside the string inside the snippet, but there is not guarantee that is true with any given update. In this particular case the conflict with Prototype had to do with something going on in the snippet code so this will keep happening specifically until the entire snippet is replaced. Here is the version associated with v2.4.2

// Rollbar Snippet
!function(r){function e(n){if(o[n])return o[n].exports;var t=o[n]={exports:{},id:n,loaded:!1};return r[n].call(t.exports,t,t.exports,e),t.loaded=!0,t.exports}var o={};return e.m=r,e.c=o,e.p="",e(0)}([function(r,e,o){"use strict";var n=o(1),t=o(4);_rollbarConfig=_rollbarConfig||{},_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||"https://cdnjs.cloudflare.com/ajax/libs/rollbar.js/2.4.2/rollbar.min.js",_rollbarConfig.async=void 0===_rollbarConfig.async||_rollbarConfig.async;var a=n.setupShim(window,_rollbarConfig),l=t(_rollbarConfig);window.rollbar=n.Rollbar,a.loadFull(window,document,!_rollbarConfig.async,_rollbarConfig,l)},function(r,e,o){"use strict";function n(r){return function(){try{return r.apply(this,arguments)}catch(r){try{console.error("[Rollbar]: Internal error",r)}catch(r){}}}}function t(r,e){this.options=r,this._rollbarOldOnError=null;var o=d++;this.shimId=function(){return o},"undefined"!=typeof window&&window._rollbarShims&&(window._rollbarShims[o]={handler:e,messages:[]})}function a(r,e){if(r){var o=e.globalAlias||"Rollbar";if("object"==typeof r[o])return r[o];r._rollbarShims={},r._rollbarWrappedError=null;var t=new i(e);return n(function(){e.captureUncaught&&(t._rollbarOldOnError=r.onerror,s.captureUncaughtExceptions(r,t,!0),s.wrapGlobals(r,t,!0)),e.captureUnhandledRejections&&s.captureUnhandledRejections(r,t,!0);var n=e.autoInstrument;return e.enabled!==!1&&(void 0===n||n===!0||"object"==typeof n&&n.network)&&r.addEventListener&&(r.addEventListener("load",t.captureLoad.bind(t)),r.addEventListener("DOMContentLoaded",t.captureDomContentLoaded.bind(t))),r[o]=t,t})()}}function l(r){return n(function(){var e=this,o=Array.prototype.slice.call(arguments,0),n={shim:e,method:r,args:o,ts:new Date};window._rollbarShims[this.shimId()].messages.push(n)})}var i,s=o(2),d=0,c=o(3),p=function(r,e){return new t(r,e)};i=c.curry?c.curry(p):c.bind(null,p),t.prototype.loadFull=function(r,e,o,t,a){var l=function(){var e;if(void 0===r._rollbarDidLoad){e=new Error("rollbar.js did not load");for(var o,n,t,l,i=0;o=r._rollbarShims[i++];)for(o=o.messages||[];n=o.shift();)for(t=n.args||[],i=0;i<t.length;++i)if(l=t[i],"function"==typeof l){l(e);break}}"function"==typeof a&&a(e)},i=!1,s=e.createElement("script"),d=e.getElementsByTagName("script")[0],c=d.parentNode;s.crossOrigin="",s.src=t.rollbarJsUrl,o||(s.async=!0),s.onload=s.onreadystatechange=n(function(){if(!(i||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState)){s.onload=s.onreadystatechange=null;try{c.removeChild(s)}catch(r){}i=!0,l()}}),c.insertBefore(s,d)},t.prototype.wrap=function(r,e,o){try{var n;if(n="function"==typeof e?e:function(){return e||{}},"function"!=typeof r)return r;if(r._isWrap)return r;if(!r._rollbar_wrapped&&(r._rollbar_wrapped=function(){o&&"function"==typeof o&&o.apply(this,arguments);try{return r.apply(this,arguments)}catch(o){var e=o;throw e&&("string"==typeof e&&(e=new String(e)),e._rollbarContext=n()||{},e._rollbarContext._wrappedSource=r.toString(),window._rollbarWrappedError=e),e}},r._rollbar_wrapped._isWrap=!0,r.hasOwnProperty))for(var t in r)r.hasOwnProperty(t)&&(r._rollbar_wrapped[t]=r[t]);return r._rollbar_wrapped}catch(e){return r}};for(var u="log,debug,info,warn,warning,error,critical,global,configure,handleUncaughtException,handleUnhandledRejection,captureEvent,captureDomContentLoaded,captureLoad".split(","),f=0;f<u.length;++f)t.prototype[u[f]]=l(u[f]);r.exports={setupShim:a,Rollbar:i}},function(r,e){"use strict";function o(r,e,o){if(r){var t;"function"==typeof e._rollbarOldOnError?t=e._rollbarOldOnError:r.onerror&&!r.onerror.belongsToShim&&(t=r.onerror,e._rollbarOldOnError=t);var a=function(){var o=Array.prototype.slice.call(arguments,0);n(r,e,t,o)};a.belongsToShim=o,r.onerror=a}}function n(r,e,o,n){r._rollbarWrappedError&&(n[4]||(n[4]=r._rollbarWrappedError),n[5]||(n[5]=r._rollbarWrappedError._rollbarContext),r._rollbarWrappedError=null),e.handleUncaughtException.apply(e,n),o&&o.apply(r,n)}function t(r,e,o){if(r){"function"==typeof r._rollbarURH&&r._rollbarURH.belongsToShim&&r.removeEventListener("unhandledrejection",r._rollbarURH);var n=function(r){var o,n,t;try{o=r.reason}catch(r){o=void 0}try{n=r.promise}catch(r){n="[unhandledrejection] error getting `promise` from event"}try{t=r.detail,!o&&t&&(o=t.reason,n=t.promise)}catch(r){t="[unhandledrejection] error getting `detail` from event"}o||(o="[unhandledrejection] error getting `reason` from event"),e&&e.handleUnhandledRejection&&e.handleUnhandledRejection(o,n)};n.belongsToShim=o,r._rollbarURH=n,r.addEventListener("unhandledrejection",n)}}function a(r,e,o){if(r){var n,t,a="EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload".split(",");for(n=0;n<a.length;++n)t=a[n],r[t]&&r[t].prototype&&l(e,r[t].prototype,o)}}function l(r,e,o){if(e.hasOwnProperty&&e.hasOwnProperty("addEventListener")){for(var n=e.addEventListener;n._rollbarOldAdd&&n.belongsToShim;)n=n._rollbarOldAdd;var t=function(e,o,t){n.call(this,e,r.wrap(o),t)};t._rollbarOldAdd=n,t.belongsToShim=o,e.addEventListener=t;for(var a=e.removeEventListener;a._rollbarOldRemove&&a.belongsToShim;)a=a._rollbarOldRemove;var l=function(r,e,o){a.call(this,r,e&&e._rollbar_wrapped||e,o)};l._rollbarOldRemove=a,l.belongsToShim=o,e.removeEventListener=l}}r.exports={captureUncaughtExceptions:o,captureUnhandledRejections:t,wrapGlobals:a}},function(r,e){"use strict";function o(r,e){this.impl=r(e,this),this.options=e,n(o.prototype)}function n(r){for(var e=function(r){return function(){var e=Array.prototype.slice.call(arguments,0);if(this.impl[r])return this.impl[r].apply(this.impl,e)}},o="log,debug,info,warn,warning,error,critical,global,configure,handleUncaughtException,handleUnhandledRejection,_createItem,wrap,loadFull,shimId,captureEvent,captureDomContentLoaded,captureLoad".split(","),n=0;n<o.length;n++)r[o[n]]=e(o[n])}o.prototype._swapAndProcessMessages=function(r,e){this.impl=r(this.options);for(var o,n,t;o=e.shift();)n=o.method,t=o.args,this[n]&&"function"==typeof this[n]&&("captureDomContentLoaded"===n||"captureLoad"===n?this[n].apply(this,[t[0],o.ts]):this[n].apply(this,t));return this},r.exports=o},function(r,e){"use strict";r.exports=function(r){return function(e){if(!e&&!window._rollbarInitialized){r=r||{};for(var o,n,t=r.globalAlias||"Rollbar",a=window.rollbar,l=function(r){return new a(r)},i=0;o=window._rollbarShims[i++];)n||(n=o.handler),o.handler._swapAndProcessMessages(l,o.messages);window[t]=n,window._rollbarInitialized=!0}}}}]);
// End Rollbar Snippet

@JasonSooter
Copy link

@rokob I have replaced the snippet. I'm now receiving a fair amount of other errors in the console regarding the rollbar line of code. You can see them by going to https://www.theorganicbloom.com. Not really sure what to do about them

@rivkahstandig3636 rivkahstandig3636 modified the milestones: v2.4.3, v2.4.5 Aug 2, 2018
@jessewgibbs
Copy link
Contributor

I'm closing this issue since the original issue is fixed. @functionalStoic if you're still running into problems, could you open a new issue w/ the details?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants