diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a4be436..7d4acd93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # CHANGELOG +## 0.3.7 + + - Catch localStorage errors. + +## 0.3.6 + + - Fixed S3 typo. + ## 0.3.5 - Fixed server push. diff --git a/gun.js b/gun.js index ced97703..f948bbf2 100644 --- a/gun.js +++ b/gun.js @@ -1140,8 +1140,8 @@ ;(function(exports){ function s(){} - s.put = function(key, val){ return store.setItem(key, Gun.text.ify(val)) } - s.get = function(key, cb){ /*setTimeout(function(){*/ return cb(null, Gun.obj.ify(store.getItem(key) || null)) /*},1)*/} + s.put = function(key, val, cb){ try{ store.setItem(key, Gun.text.ify(val)) }catch(e){if(cb)cb(e)} } + s.get = function(key, cb){ /*setTimeout(function(){*/ try{ cb(null, Gun.obj.ify(store.getItem(key) || null)) }catch(e){cb(e)} /*},1)*/} s.del = function(key){ return store.removeItem(key) } var store = this.localStorage || {setItem: function(){}, removeItem: function(){}, getItem: function(){}}; exports.store = s; @@ -1192,7 +1192,7 @@ (opt.headers = Gun.obj.copy(tab.headers)).id = tab.msg(); Gun.is.graph(graph, function(node, soul){ if(!gun.__.graph[soul]){ return } - tab.store.put(tab.prefix + soul, gun.__.graph[soul]); + tab.store.put(tab.prefix + soul, gun.__.graph[soul], function(err){if(err){ cb({err: err}) }}); }); if(!(cb.local = opt.local)){ tab.request.s[opt.headers.id] = tab.error(cb, "Error: Put failed!"); diff --git a/package.json b/package.json index 8c3a9a4f..2db6a0ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.3.6", + "version": "0.3.7", "description": "Graph engine", "main": "index.js", "scripts": { diff --git a/test/common.js b/test/common.js index f4ff81e4..2caa79e8 100644 --- a/test/common.js +++ b/test/common.js @@ -3780,6 +3780,22 @@ describe('Gun', function(){ } }); }); + + it("localStorage", function(done){ + var localStorage = localStorage || {clear:function(){}}; + localStorage.clear(); + var gun = Gun(); + + + var text = Gun.text.random(1024 * 1024 * 6); + gun.put({i: text}, function(err, ok){ + if(done.c){ return } + if(!err){ return done() } + var text = "If you are seeing this message, it means the localStorage error was caught successfully rather than it crashing and stopping replication to peers. Also, the error is now reported back to you via the put callback. Here it is!"; + localStorage.clear(); + done(); done.c = 1; + }); + }); }); describe('Streams', function(){