# JavaScript Error Reports - missing source, line and column number

**URL:** https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115
**Category:** Bug
**Tags:** rest-api
**Created:** [January 17, 2015, 1:12am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115 "2015-01-17T01:12:07Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [January 17, 2015, 1:12am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/1 "2015-01-17T01:12:07Z")

</div>

I’m seeing the source, line and column number missing from most of the JavaScript error reports

Obviously these may either indicate an actual problem / incompatibility with a device.

Here is a sample:

 ![](https://global.discourse-cdn.com/meta/original/3X/6/d/6d8f4413aaf291f8029e23a3764bf984d3b7763e.png)

Each of these is a different User Agent / browser:

- `Mozilla/5.0 (Linux; Android 4.4.2; SM-N9005 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.93 Mobile Safari/537.36`
- `Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko/20100101 Firefox/12.0`
- `Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53`
- `Mozilla/5.0 (Android; Mobile; rv:36.0) Gecko/36.0 Firefox/36.0`
- `Mozilla/5.0 (Windows NT 5.1; rv:34.0) Gecko/20100101 Firefox/34.0`
- `Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 620; Vodafone) like Gecko`

I understand that some of these may not all be “supported” browsers.

**I was thinking maybe something obvious is broken in the capture of the source, line and column number code.**

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [January 17, 2015, 1:37am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/2 "2015-01-17T01:37:33Z")

</div>

These simply need to be suppressed.

I went ahead and checked in this regex which should do it, though it might need some refinement

`(?m)\AScript error\..*?Line: 0.*?Column: 0`

That gets the zero cases that I see in my logs of the form

```
Script error.
Url: 
Line: 0
Column: 0
Window Location: http://discourse.codinghorror.com/t/the-god-login/2924/19

```

I’ll do another one for completely empty. Can you paste the raw text in please?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [January 17, 2015, 1:38am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/3 "2015-01-17T01:38:17Z")

</div>

Aha I think I see one:

```
Url: 
Line: 
Column: 
Window Location: http://discourse.codinghorror.com/faq

```

Will do that in a bit

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [January 17, 2015, 2:06am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/4 "2015-01-17T02:06:35Z")

</div>

> [@codinghorror](#):
>
> These simply need to be suppressed

@codinghorror could I ask your reasoning behind this?  
Is it that there is never a way of getting the source file / line numbers from these browsers?

If this is the case perhaps we should still keep some kind of count of them to ensure error captures don’t suddenly spike and us not be aware of it.

EDIT: In terms of a regex - this is a more likely fit:

```
\AUrl:\s+Line:\s+Column:\s+Window Location:\s+

```

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [January 17, 2015, 4:42am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/5 "2015-01-17T04:42:43Z")

</div>

I think this regex is better:

```
/(?m)\A(Script error\.| |)\nUrl: [^\n]*\nLine: 0?\nColumn: 0?\n/m

```

Submitted it [here](https://github.com/discourse/discourse/pull/3104/files).

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 17, 2015, 6:03am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/6 "2015-01-17T06:03:08Z")

</div>

My intention was always just to collapse similar errors and retain counts, have not had a chance to do so yet, this is a stop gap

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [January 17, 2015, 7:45am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/7 "2015-01-17T07:45:56Z")

</div>

Still, the **useless client submitted JavaScript errors** should be removed as noise. Maybe they have a malfunctioning browser, maybe they are browsing with IE7, who knows.

Anything with

```
Line: 0
Column: 0

```

or

```
Line: 
Column:

```

Is quite useless. I updated to

`(?m).*?Line: (?:\D|0).*?Column: (?:\D|0)`

and that works on all cases in the errors I have in my log at [discourse.codinghorror.com](http://discourse.codinghorror.com) at least.

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [January 19, 2015, 3:38am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/8 "2015-01-19T03:38:04Z")

</div>

I believe I have found the cause of these error reports missing line numbers.

I could be wrong - but I thought I would share as I currently I debugging in production and source and line numbers are off a bit…

Not quite the root cause - but I can cause it in Google Chrome 39 dependably.

I believe that when an AJAX call fails for whatever reason we are seeing these JavaScript errors with no source, line number or column number.

###Steps to reproduce

1. Set Discourse instance to “Read-Only” mode
2. Open Chrome to topic page
3. Open debug console Ctrl + Shift + i
4. Copy this line onto clipboard  
`window.onerror = function(m, u, l, c, errorObj) { console.log(m, u, l, c, errorObj, errorObj.stack); }`
5. Refresh page
6. Wait for page to load
7. As soon as it seems complete Paste and Execute the line copied to the clipboard.

Note that all we have really done here is replace this function:

> <https://github.com/discourse/logster/blob/bbd1a7ae11ad10c7961092eb085439dbeab79e0b/vendor/assets/javascripts/logster.js.erb#L10>

With one that will allow Chrome to help us find the source of the error.  
And if you were using un-minified sources you could just as easy use `window.onerror = null` to get better debugging in Chrome.

###Expected Output  
Lines to be output including line numbers

###Actual Output

```
 undefined null null null Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: undefined

```

**Note the source, line and column numbers are null.**

###explanation

Note that the object output is from the Timing call here:

> <https://github.com/discourse/discourse/blob/f66c39c63bfa57318f742b672b02a02ab18b68a3/app/assets/javascripts/discourse/lib/screen_track.js#L123>

Using the Ajax call here:

> <https://github.com/discourse/discourse/blob/271374a8c62b247d826f8bdfc648da8f36dc8618/app/assets/javascripts/discourse/mixins/ajax.js#L43>

So to repeat:  
**I believe that when an AJAX call fails for whatever reason we are seeing these JavaScript errors with no source, line number or column number.**

I’m not just thinking the timing AJAX calls have this issue - perhaps others do too?

**Until this is proven true or false I believe suppression is perhaps the wrong thing to do and perhaps indicative of an actual problem existing.**

Feel free to call me crazy, slap me about and tell me I’m wrong.

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [January 19, 2015, 3:47am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/9 "2015-01-19T03:47:48Z")

</div>

> [@codinghorror](#):
>
> Maybe they have a malfunctioning browser, maybe they are browsing with IE7, who knows.

I also checked and all these browsers have this problem in my logs:

- Chrome 39 - Windows XP
- Chrome 39 - Linux - Sony Xperia Z3
- Firefox/35.0 - Windows XP
- Firefox/35.0 - Windows 7
- Safari - iOS 8.1.2 (iPad)
- Safari - iOS 8.1.2 (iPhone)
- Chrome 39 - Samsung GALAXY Note 3 - Android 4.2.2
- Chrome 39 - Windows 8.1
- Chrome 28 - Samsung Galaxy S4 (GT-I9505)
- Chrome 37 (Amazon Silk) - Kindle Fire HD - Android 4.0.3
- Firefox 34.0 - Windows 7
- Chrome 39 - Sony XPERIA™ Z2 Tablet
- IE9 - Windows Vista
- Firefox 35 - Windows XP
- Firefox 35 - Windows 8.1
- IE11 - Windows 7
- Safari - iOS 6.1 (iPhone)
- Chrome 28 - Samsung Galaxy S5 - Android 4.2.2

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [January 19, 2015, 3:55am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/10 "2015-01-19T03:55:47Z")

</div>

I do not agree @deanmarktaylor. Looking at the logs on meta they are full of exactly this:

```plaintext
HTTP_HOST: meta.discourse.org
REQUEST_URI: /logs/report_js_error
REQUEST_METHOD: POST
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
HTTP_ACCEPT: */*
HTTP_REFERER: https://meta.discourse.org/t/nocaptcha-support/24107/1
HTTP_X_FORWARDED_FOR: 70.117.105.168, 10.0.0.202
HTTP_X_REAL_IP: 10.0.0.202

params:
  url: 
  line: 
  column: 
  window_location: https://meta.discourse.org/t/nocaptcha-support/24107/1

```

Hundreds of these, just like this. Zero backtrace, zero context, just a bunch of crying wolf with no information whatsoever.

And crying wolf is extremely harmful. It devalues any real substantive errors you might find in logs when they are cluttered with hundreds of useless noise entries, submitted by browser clients for who knows why.

I do not find it particularly illuminating to have a new “error” log entry every time a browser client HTTP ajax request fails… do you?

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [January 19, 2015, 4:02am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/11 "2015-01-19T04:02:26Z")

</div>

I’m saying that the error capture is broken because of the overrides and implementation of error handling for Discourse AJAX handling or some other element related to it.

The error might not even get to sending to the logs if it was handled correctly on the client.

EDIT: Somehow the promise / error object is getting pushed to `onerror` incorrectly instead of the correct error detail.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [January 19, 2015, 4:18am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/12 "2015-01-19T04:18:40Z")

</div>

That may be, and improvements in this area are welcome, but client “errors” without a line number or any useful accompanying information are not helpful to ever record. This will continue to be true now, and in the future, whether failed HTTP JavaScript call “errors” are handled better or not.

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [January 19, 2015, 4:27am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/13 "2015-01-19T04:27:01Z")

</div>

Wouldn’t you rather not suppress for now so help identify the existence of real errors / incorrectly coded things?

If it’s then proven to just be a browser issue and not some coding error then suppress it?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [January 19, 2015, 4:28am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/14 "2015-01-19T04:28:53Z")

</div>

I trust real user reports (even second hand or anecdotal reports) much, much more than random local browser JavaScript freakouts that get recorded on the server.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [January 19, 2015, 4:41am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/15 "2015-01-19T04:41:27Z")

</div>

Putting discussion about error suppression vs. error handling aside @DeanMarkTaylor are you saying you think it’s Discourse being in Read Only mode that is causing the AJAX FAILs and _not_ a browser glitch?

---

<div class="post-metadata">

### Author: ![DeanMarkTaylor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/deanmarktaylor/32/102462_2.png) [@DeanMarkTaylor](https://meta.discourse.org/u/DeanMarkTaylor)
#### Post date: [January 19, 2015, 4:44am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/16 "2015-01-19T04:44:58Z")

</div>

I’m saying putting Discourse into Read-Only is one way of causing these errors…

and yes the AJAX calls do fail with 405’s I believe.

… I believe in this case (read-only etc) it’s not a browser glitch and is a coding error.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [July 3, 2015, 5:34am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/17 "2015-07-03T05:34:50Z")

</div>

We generally suppress client JS errors that lack all line and column info now.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [July 3, 2015, 5:34am UTC](https://meta.discourse.org/t/javascript-error-reports-missing-source-line-and-column-number/24115/18 "2015-07-03T05:34:54Z")

</div>


