mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-31 01:38:08 -05:00
Catch and log errors setting local storage values.
This commit is contained in:
@@ -36,6 +36,35 @@ r.ajax = function(request) {
|
||||
return $.ajax(request)
|
||||
}
|
||||
|
||||
store.safeGet = function(key, errorValue) {
|
||||
// errorValue defaults to undefined, equivalent to the key being unset.
|
||||
try {
|
||||
return store.get(key)
|
||||
} catch (err) {
|
||||
r.sendError('Unable to read storage key "%(key)s" (%(err)s)'.format({
|
||||
key: key,
|
||||
err: err
|
||||
}))
|
||||
// TODO: reset value to errorValue?
|
||||
return errorValue
|
||||
}
|
||||
}
|
||||
|
||||
store.safeSet = function(key, val) {
|
||||
// swallow exceptions upon storage set for non-trivial operations. returns
|
||||
// a boolean value indicating success.
|
||||
try {
|
||||
store.set(key, val)
|
||||
return true
|
||||
} catch (err) {
|
||||
r.warn('Unable to set storage key "%(key)s" (%(err)s)'.format({
|
||||
key: key,
|
||||
err: err
|
||||
}))
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
r.setupBackbone = function() {
|
||||
Backbone.emulateJSON = true
|
||||
Backbone.ajax = r.ajax
|
||||
|
||||
@@ -610,9 +610,9 @@ r.multi.ListingChooser = Backbone.View.extend({
|
||||
this.$el.addClass('initialized')
|
||||
|
||||
// transition collapsed state to server pref
|
||||
if (store.get('ui.collapse.listingchooser') == true) {
|
||||
if (store.safeGet('ui.collapse.listingchooser') == true) {
|
||||
this.toggleCollapsed(true)
|
||||
store.remove('ui.collapse.listingchooser')
|
||||
store.safeSet('ui.collapse.listingchooser')
|
||||
}
|
||||
|
||||
// HACK: fudge page heights for long lists of multis / short pages
|
||||
|
||||
@@ -3,10 +3,10 @@ r.ui.init = function() {
|
||||
if ($.cookie('reddit_first')) {
|
||||
// save welcome seen state and delete obsolete cookie
|
||||
$.cookie('reddit_first', null, {domain: r.config.cur_domain})
|
||||
store.set('ui.shown.welcome', true)
|
||||
} else if (store.get('ui.shown.welcome') != true) {
|
||||
store.safeSet('ui.shown.welcome', true)
|
||||
} else if (store.safeGet('ui.shown.welcome') != true) {
|
||||
$('.infobar.welcome').show()
|
||||
store.set('ui.shown.welcome', true)
|
||||
store.safeSet('ui.shown.welcome', true)
|
||||
}
|
||||
|
||||
// mobile suggest infobar
|
||||
|
||||
@@ -13,7 +13,7 @@ r.ui.Collapse = function(el, target, key) {
|
||||
r.ui.Base.call(this, el)
|
||||
this.target = target
|
||||
this.key = 'ui.collapse.' + key
|
||||
this.isCollapsed = store.get(this.key) == true
|
||||
this.isCollapsed = store.safeGet(this.key) == true
|
||||
this.$el.click($.proxy(this, 'toggle', null, false))
|
||||
this.toggle(this.isCollapsed, true)
|
||||
}
|
||||
@@ -33,7 +33,7 @@ r.ui.Collapse.prototype = {
|
||||
}
|
||||
|
||||
this.isCollapsed = collapsed
|
||||
store.set(this.key, collapsed)
|
||||
store.safeSet(this.key, collapsed)
|
||||
this.update()
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user