Skip to content

Commit

Permalink
Remove browser error reporting
Browse files Browse the repository at this point in the history
No one look at it. It also contains browser extension errors and the
included error message isn't useful either.
  • Loading branch information
nanaya committed Nov 23, 2024
1 parent 9f7afe8 commit 1baaedc
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 97 deletions.
11 changes: 0 additions & 11 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,6 @@ def set_avatar
@post = Post.find(params[:id])
end

def error
report = params[:report]

file = "#{Rails.root}/log/user_errors.log"
File.open(file, "a") do |f|
f.write(report.to_s + "\n\n\n-------------------------------------------\n\n\n")
end

render json: { success: true }
end

private

def get_view_name_for_edit(param)
Expand Down
3 changes: 1 addition & 2 deletions app/javascript/src/classes/tag_completion.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ export default class TagCompletion
results.each (tag) ->
m = tag.match(/(\d+)`([^`]*)`(([^ ]*)`)? /)
if !m
ReportError 'Unparsable cached tag: \'' + tag + '\'', null, null, null, null
throw 'Unparsable cached tag: \'' + tag + '\''
throw "Unparsable cached tag: '#{tag}'"
tag = m[2]
tag_type = Post.tag_type_names[m[1]]
aliases = m[4]
Expand Down
83 changes: 0 additions & 83 deletions app/javascript/src/legacy/common.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ window.InitAdvancedEditing = ->
$(document.documentElement).removeClassName 'hide-advanced-editing'
return

window.onerror = (error, file, line) ->
ReportError error, file, line, null
return

### Return the squared distance between two points. ###
window.distance_squared = (x1, y1, x2, y2) ->
(x1 - x2) ** 2 + (y1 - y2) ** 2
Expand Down Expand Up @@ -539,82 +535,3 @@ window.TrackFocus = ->
return
).bindAsEventListener(this)
return

window.FormatError = (message, file, line, exc, info) ->
report = ''
report += 'Error: ' + message + '\n'
if info?
report += info
report += 'UA: ' + window.navigator.userAgent + '\n'
report += 'URL: ' + window.location.href + '\n'
cookies = document.cookie
cookies = cookies.replace(/(pass_hash)=[0-9a-f]{40}/, '$1=(removed)')
try
report += 'Cookies: ' + decodeURIComponent(cookies) + '\n'
catch e
report += 'Cookies (couldn\'t decode): ' + cookies + '\n'
if 'localStorage' of window

### FF's localStorage is broken; we can't iterate over it. Name the keys we use explicitly. ###

keys = []
try
for storageKey of localStorage
keys.push storageKey
catch e
keys = [
'sample_urls'
'sample_url_fifo'
'tag_data'
'tag_data_version'
'recent_tags'
'tag_data_format'
]
i = 0
while i < keys.length
key = keys[i]
try
if !(key of localStorage)
++i
continue
data = localStorage[key]
length = data.length
if data.length > 512
data = data.slice(0, 512)
report += 'localStorage.' + key + ' (size: ' + length + '): ' + data + '\n'
catch e
report += '(ignored errors retrieving localStorage for ' + key + ': ' + e + ')\n'
++i
if exc and exc.stack
report += '\n' + exc.stack + '\n'
if file
report += 'File: ' + file
if line?
report += ' line ' + line + '\n'
report

window.reported_error = false

window.ReportError = (message, file, line, exc, info) ->
if navigator.userAgent.match(/.*MSIE [67]/)
return

### Only attempt to report an error once per page load. ###

if window.reported_error
return
window.reported_error = true

### Only report an error at most once per hour. ###

if document.cookie.indexOf('reported_error=1') != -1
return
expiration = new Date
expiration.setTime expiration.getTime() + 60 * 60 * 1000
document.cookie = 'reported_error=1; path=/; expires=' + expiration.toGMTString()
report = FormatError((if exc then exc.message else message), file, line, exc, info)
try
jQuery.post '/user/error.json', report: report
catch e
alert 'Error: ' + e
return
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@
match "user/change_password", via: [ :post, :get ]
post "user/check"
match "user/edit", via: [ :post, :get ]
match "user/error", via: [ :post, :get ]
match "user/home", via: [ :post, :get ]
match "user/invites", via: [ :post, :get ]
match "user/login", via: [ :post, :get ]
Expand Down

0 comments on commit 1baaedc

Please sign in to comment.