RaygunJS throws exception when trying to report error if "tags" is not an array

billhannah

Posted on
Nov 07 2017

In some code paths, the tags option is converted to an array (mergeArray(_tags, tags)) before sending. However, in some cases the new tag UnhandledException is pushed onto the tags array. If options.tags is not an array, a new error is thrown when the new tag is added. As a result, the error is not reported.

The following code is to blame:

if(!contains(options.tags, 'UnhandledException')) { options.tags.push('UnhandledException'); }

This code path will only be hit if the error was not user triggered and is the only code path that will not handle the tags property not being an array.


ubermouse

Posted on
Nov 07 2017

Hi Bill,

Sorry you ran into this issue, I'll look at getting a fix out as soon as I can. I'll update you here when the fix is out.

Regards, Taylor


ubermouse

Posted on
Nov 07 2017

Hi Bill,

Can you give me a bit more information on this? I suspected you were talking about the functionality to set withTags to a function that returns the tags, but that works correctly with the UnhandledException tag. What are you setting the tags to? withTags is only supposed to be set to either an array of tags or a function that will return an array of tags.

Regards, Taylor


billhannah

Posted on
Nov 07 2017

Sure. You are correct, it should only work with functions or arrays. But it sort of works with tags set to a string.

We recently upgraded RaygunJS to from version v.1.12.0 to version v2.5.3 in early October. After the upgrade, some errors that were previously reported were no longer being reported.

An internal investigation found that on pages where the tags option was set to a string instead of an array of strings, some errors were not being reported.

Because most errors were still being reported, we did not notice the issue for weeks.

So, the real issue is that setting tags to a string does work most of the time. In other code paths, it appears that the string is coerced into an array before being sent. This appears to be the only code path where a string will not work. Now some errors will not be reported but others will, whereas before the addition of the the referenced code, all errors would have been reported.


ubermouse

Posted on
Nov 08 2017

Hi Bill,

Can you give me a bit more information on why you are setting the tags to a string and not an array? Just want to better understand the use case.

Thanks, Taylor


billhannah

Posted on
Nov 08 2017

User error. It was misconfigured years ago and then copied to other areas of the site. The reason for raising the issue (even though it was bad configuration) is that even though it is misconfigured, it usually works except for this 1 newer code path that throws an exception when preparing the bug report for sending. So some error reports will be lost. The only reason we discovered it was misconfigured is we noticed some errors were not getting reported. Maybe a better "fix" would be to always throw an error when loading RaygunJS if the tags are misconfigured.


ubermouse

Posted on
Nov 09 2017

Hi Bill,

The simplest way to fix this crash was to just add support for tags being a string in that case. It will now wrap the tags in an array if it is a string before pushing the UnhandledException tag onto the array. This fix is in v2.8.3 which has been released on NPM and the CDN.

Regards, Taylor


billhannah

Posted on
Nov 09 2017

Thank you so much Taylor.


Reply