Skip to content

Commit

Permalink
Use console.warn, console.error
Browse files Browse the repository at this point in the history
  • Loading branch information
atjn committed Aug 21, 2023
1 parent f882b86 commit cc38e51
Show file tree
Hide file tree
Showing 22 changed files with 59 additions and 43 deletions.
4 changes: 2 additions & 2 deletions as.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
$.as.route(location.hash.slice(1));
$(JOY.start = JOY.start || function(){ $.as(document, gun, null, JOY.opt) });

if($('body').attr('peers')){ (console.warn || console.log)('Warning: Please upgrade <body peers=""> to https://github.com/eraeco/joydb#peers !') }
if($('body').attr('peers')){ console.warn('Please upgrade <body peers=""> to https://github.com/eraeco/joydb#peers !') }

});
;(function(){ // need to isolate into separate module!
Expand All @@ -228,7 +228,7 @@
var opt = joy.opt = window.CONFIG || {}, peers;
$('link[type=peer]').each(function(){ (peers || (peers = [])).push($(this).attr('href')) });
!window.gun && (opt.peers = opt.peers || peers || (function(){
(console.warn || console.log)('Warning: No peer provided, defaulting to DEMO peer. Do not run in production, or your data will be regularly wiped, reset, or deleted. For more info, check https://github.com/eraeco/joydb#peers !');
console.warn('No peer provided, defaulting to DEMO peer. Do not run in production, or your data will be regularly wiped, reset, or deleted. For more info, check https://github.com/eraeco/joydb#peers !');
return ['https://gunjs.herokuapp.com/gun'];
}()));
window.gun = window.gun || Gun(opt);
Expand Down
2 changes: 1 addition & 1 deletion examples/react-native/src/extensions/sea.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@
(cb || noop)({ok: 0});
});
} catch (e) {
Gun.log('User.delete failed! Error:', e);
Gun.error('User.delete failed! Error:', e);
}
return gun;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/vanilla/video.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
record.ing.start()
}

function error(err) { console.log(err) }
function error(err) { console.error(err) }

if (type === 'Camera') {
navigator.getMedia({ video: true, audio: true }, load, error)
Expand Down
14 changes: 8 additions & 6 deletions gun.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
var ERR = "Error: Invalid graph!";
var cut = function(s){ return " '"+(''+s).slice(0,9)+"...' " }
var L = JSON.stringify, MD = 2147483647, State = Gun.state;
var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}};
var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.warn("You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}};

}());

Expand Down Expand Up @@ -1380,12 +1380,14 @@
var noop = function(){}
var parse = JSON.parseAsync || function(t,cb,r){ var u, d = +new Date; try{ cb(u, JSON.parse(t,r), json.sucks(+new Date - d)) }catch(e){ cb(e) } }
var json = JSON.stringifyAsync || function(v,cb,r,s){ var u, d = +new Date; try{ cb(u, JSON.stringify(v,r,s), json.sucks(+new Date - d)) }catch(e){ cb(e) } }
json.sucks = function(d){ if(d > 99){ console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } }
json.sucks = function(d){ if(d > 99){ console.warn("JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } }

function Mesh(root){
var mesh = function(){};
var opt = root.opt || {};
opt.log = opt.log || console.log;
opt.warn = opt.warn || console.warn;
opt.error = opt.error || console.error;
opt.gap = opt.gap || opt.wait || 0;
opt.max = opt.max || (opt.memory? (opt.memory * 999 * 999) : 300000000) * 0.3;
opt.pack = opt.pack || (opt.max * 0.01 * 0.01);
Expand Down Expand Up @@ -1619,7 +1621,7 @@
if(!tmp){ return }
if(t? 3 > tmp.length : !tmp.length){ return } // TODO: ^
if(!t){try{tmp = (1 === tmp.length? tmp[0] : JSON.stringify(tmp));
}catch(e){return opt.log('DAM JSON stringify error', e)}}
}catch(e){return opt.error('DAM JSON stringify error', e)}}
if(!tmp){ return }
send(tmp, peer);
}
Expand Down Expand Up @@ -1667,7 +1669,7 @@
var tmp = +(new Date); tmp = (tmp - (peer.met||tmp));
mesh.bye.time = ((mesh.bye.time || tmp) + tmp) / 2;
}
mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) }
mesh.hear['!'] = function(msg, peer){ opt.error('Error:', msg.err) }
mesh.hear['?'] = function(msg, peer){
if(msg.pid){
if(!peer.pid){ peer.pid = msg.pid }
Expand Down Expand Up @@ -1794,7 +1796,7 @@
var noop = function(){}, store, u;
try{store = (Gun.window||noop).localStorage}catch(e){}
if(!store){
Gun.log("Warning: No localStorage exists to persist data to!");
Gun.warn("No localStorage exists to persist data to!");
store = {setItem: function(k,v){this[k]=v}, removeItem: function(k){delete this[k]}, getItem: function(k){return this[k]}};
}

Expand Down Expand Up @@ -1862,7 +1864,7 @@
;(function(){
var u;
if(''+u == typeof Gun){ return }
var DEP = function(n){ console.warn("Warning! Deprecated internal utility will break in next version:", n) }
var DEP = function(n){ console.warn("Deprecated internal utility will break in next version:", n) }
// Generic javascript utilities.
var Type = Gun;
//Type.fns = Type.fn = {is: function(fn){ return (!!fn && fn instanceof Function) }}
Expand Down
2 changes: 1 addition & 1 deletion gun.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/book.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;(function(){ // Book
console.log("Warning: Book is in alpha!");
console.warn("Book is in alpha!");
var sT = setTimeout, B = sT.Book || (sT.Book = function(text){
var b = function book(word, is){
var has = b.all[word], p;
Expand Down
10 changes: 6 additions & 4 deletions lib/radisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

opt = opt || {};
opt.log = opt.log || console.log;
opt.warn = opt.warn || console.warn;
opt.error = opt.error || console.error;
opt.file = String(opt.file || 'radata');
var has = (Radisk.has || (Radisk.has = {}))[opt.file];
if(has){ return has }
Expand All @@ -25,16 +27,16 @@
var ST = 0;

if(!opt.store){
return opt.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");
return opt.error("Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");
}
if(!opt.store.put){
return opt.log("ERROR: Radisk needs `store.put` interface with `(file, data, cb)`!");
return opt.error("Radisk needs `store.put` interface with `(file, data, cb)`!");
}
if(!opt.store.get){
return opt.log("ERROR: Radisk needs `store.get` interface with `(file, cb)`!");
return opt.error("Radisk needs `store.get` interface with `(file, cb)`!");
}
if(!opt.store.list){
//opt.log("WARNING: `store.list` interface might be needed!");
//opt.warn("`store.list` interface might be needed!");
}

if(''+u != typeof require){ require('./yson') }
Expand Down
10 changes: 6 additions & 4 deletions lib/radisk2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

opt = opt || {};
opt.log = opt.log || console.log;
opt.warn = opt.warn || console.warn;
opt.error = opt.error || console.error;
opt.file = String(opt.file || 'radata');
var has = (Radisk.has || (Radisk.has = {}))[opt.file];
if(has){ return has }
Expand All @@ -23,16 +25,16 @@
var LOG = false;

if(!opt.store){
return opt.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");
return opt.error("Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");
}
if(!opt.store.put){
return opt.log("ERROR: Radisk needs `store.put` interface with `(file, data, cb)`!");
return opt.error("Radisk needs `store.put` interface with `(file, data, cb)`!");
}
if(!opt.store.get){
return opt.log("ERROR: Radisk needs `store.get` interface with `(file, cb)`!");
return opt.error("Radisk needs `store.get` interface with `(file, cb)`!");
}
if(!opt.store.list){
//opt.log("WARNING: `store.list` interface might be needed!");
//opt.warn("`store.list` interface might be needed!");
}

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/radisk3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;(function(){ // RAD
console.log("Warning: Experimental rewrite of RAD to use Book. It is not API compatible with RAD yet and is very alpha.");
console.warn("Experimental rewrite of RAD to use Book. It is not API compatible with RAD yet and is very alpha.");
var sT = setTimeout, Book = sT.Book, RAD = sT.RAD || (sT.RAD = function(opt){
opt = opt || {};
opt.file = String(opt.file || 'radata');
Expand Down
2 changes: 1 addition & 1 deletion lib/radmigtmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function(r){
l.push([f,v]);
});
if(l.length){
console.log("\n! ! ! WARNING ! ! !\nRAD v0.2020.x has detected OLD v0.2019.x data & automatically migrating. Automatic migration will be turned OFF in future versions! If you are just developing/testing, we recommend you reset your data. Please contact us if you have any concerns.\nThis message should only log once.")
console.warn("RAD v0.2020.x has detected OLD v0.2019.x data & automatically migrating. Automatic migration will be turned OFF in future versions! If you are just developing/testing, we recommend you reset your data. Please contact us if you have any concerns.\nThis message should only log once.")
}
var f, v;
l.forEach(function(a){
Expand Down
5 changes: 3 additions & 2 deletions lib/rfs.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
function Store(opt){
opt = opt || {};
opt.log = opt.log || console.log;
opt.error = opt.error || console.error;
opt.file = String(opt.file || 'radata');
var fs = require('fs'), u;

var store = function Store(){};
if(Store[opt.file]){
console.log("Warning: reusing same fs store and options as 1st.");
console.warn("Reusing same fs store and options as 1st.");
return Store[opt.file];
}
Store[opt.file] = store;
Expand Down Expand Up @@ -35,7 +36,7 @@ function Store(opt){
if('ENOENT' === (err.code||'').toUpperCase()){
return cb();
}
opt.log("ERROR:", err);
opt.error("ERROR:", err);
}
cb(err, data);
});
Expand Down
6 changes: 3 additions & 3 deletions lib/rindexed.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (navigator.storage && navigator.storage.estimate) {
var store = Store[opt.file], db = null, u;

if(store){
console.log("Warning: reusing same IndexedDB store and options as 1st.");
console.warn("Reusing same IndexedDB store and options as 1st.");
return Store[opt.file];
}
store = Store[opt.file] = function(){};
Expand All @@ -26,7 +26,7 @@ if (navigator.storage && navigator.storage.estimate) {
var s = store.d || (store.d = {});
store.put = function(f, d, cb){ s[f] = d; setTimeout(function(){ cb(null, 1) },250) };
store.get = function(f, cb){ setTimeout(function(){ cb(null, s[f] || u) },5) };
console.log('Warning: No indexedDB exists to persist data to!');
console.warn('No indexedDB exists to persist data to!');
return store;
}}catch(e){}

Expand All @@ -35,7 +35,7 @@ if (navigator.storage && navigator.storage.estimate) {
var o = indexedDB.open(opt.file, 1);
o.onupgradeneeded = function(eve){ (eve.target.result).createObjectStore(opt.file) }
o.onsuccess = function(){ db = o.result }
o.onerror = function(eve){ console.log(eve||1); }
o.onerror = function(eve){ console.error(eve||1); }
}; store.start();

store.put = function(key, data, cb){
Expand Down
2 changes: 1 addition & 1 deletion lib/rs3.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function Store(opt){

var store = function Store(){};
if(Store[opt.file]){
console.log("Warning: reusing same S3 store and options as 1st.");
console.warn("Reusing same S3 store and options as 1st.");
return Store[opt.file];
}
Store[opt.file] = store;
Expand Down
2 changes: 1 addition & 1 deletion lib/super.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
} else {

}
if (!peer.id) {console.log('[*** WARN] no peer.id %s', soul);}
if (!peer.id) {console.warn('No peer.id %s', soul);}
var subs = Gun.subs(soul) || null;
var tmp = subs ? subs.split(',') : [], p = at.opt.peers;
if (subs) {
Expand Down
2 changes: 1 addition & 1 deletion src/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if(typeof Gun === 'undefined'){ return }
var noop = function(){}, store, u;
try{store = (Gun.window||noop).localStorage}catch(e){}
if(!store){
Gun.log("Warning: No localStorage exists to persist data to!");
Gun.warn("No localStorage exists to persist data to!");
store = {setItem: function(k,v){this[k]=v}, removeItem: function(k){delete this[k]}, getItem: function(k){return this[k]}};
}

Expand Down
8 changes: 5 additions & 3 deletions src/mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ require('./shim');
var noop = function(){}
var parse = JSON.parseAsync || function(t,cb,r){ var u, d = +new Date; try{ cb(u, JSON.parse(t,r), json.sucks(+new Date - d)) }catch(e){ cb(e) } }
var json = JSON.stringifyAsync || function(v,cb,r,s){ var u, d = +new Date; try{ cb(u, JSON.stringify(v,r,s), json.sucks(+new Date - d)) }catch(e){ cb(e) } }
json.sucks = function(d){ if(d > 99){ console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } }
json.sucks = function(d){ if(d > 99){ console.warn("JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } }

function Mesh(root){
var mesh = function(){};
var opt = root.opt || {};
opt.log = opt.log || console.log;
opt.warn = opt.warn || console.warn;
opt.error = opt.error || console.error;
opt.gap = opt.gap || opt.wait || 0;
opt.max = opt.max || (opt.memory? (opt.memory * 999 * 999) : 300000000) * 0.3;
opt.pack = opt.pack || (opt.max * 0.01 * 0.01);
Expand Down Expand Up @@ -237,7 +239,7 @@ function Mesh(root){
if(!tmp){ return }
if(t? 3 > tmp.length : !tmp.length){ return } // TODO: ^
if(!t){try{tmp = (1 === tmp.length? tmp[0] : JSON.stringify(tmp));
}catch(e){return opt.log('DAM JSON stringify error', e)}}
}catch(e){return opt.error('DAM JSON stringify error', e)}}
if(!tmp){ return }
send(tmp, peer);
}
Expand Down Expand Up @@ -285,7 +287,7 @@ function Mesh(root){
var tmp = +(new Date); tmp = (tmp - (peer.met||tmp));
mesh.bye.time = ((mesh.bye.time || tmp) + tmp) / 2;
}
mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) }
mesh.hear['!'] = function(msg, peer){ opt.error('Error:', msg.err) }
mesh.hear['?'] = function(msg, peer){
if(msg.pid){
if(!peer.pid){ peer.pid = msg.pid }
Expand Down
15 changes: 11 additions & 4 deletions src/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,17 @@ Gun.ask = require('./ask');
var ERR = "Error: Invalid graph!";
var cut = function(s){ return " '"+(''+s).slice(0,9)+"...' " }
var L = JSON.stringify, MD = 2147483647, State = Gun.state;
var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}};
var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.warn("You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}};

}());

;(function(){
Gun.on.get = function(msg, gun){
var root = gun._, get = msg.get, soul = get['#'], node = root.graph[soul], has = get['.'];
var next = root.next || (root.next = {}), at = next[soul];

// TODO: Azarattum bug, what is in graph is not same as what is in next. Fix!

// queue concurrent GETs?
// TODO: consider tagging original message into dup for DAM.
// TODO: ^ above? In chat app, 12 messages resulted in same peer asking for `#user.pub` 12 times. (same with #user GET too, yipes!) // DAM note: This also resulted in 12 replies from 1 peer which all had same ##hash but none of them deduped because each get was different.
Expand All @@ -221,10 +224,14 @@ Gun.ask = require('./ask');
}*/
var ctx = msg._||{}, DBG = ctx.DBG = msg.DBG;
DBG && (DBG.g = +new Date);
//console.log("GET:", get, node, has);
//console.log("GET:", get, node, has, at);
//if(!node && !at){ return root.on('get', msg) }
//if(has && node){ // replace 2 below lines to continue dev?
if(!node){ return root.on('get', msg) }
if(has){
if('string' != typeof has || u === node[has]){ return root.on('get', msg) }
if('string' != typeof has || u === node[has]){
if(!((at||'').next||'')[has]){ root.on('get', msg); return }
}
node = state_ify({}, has, state_is(node, has), node[has], soul);
// If we have a key in-memory, do we really need to fetch?
// Maybe... in case the in-memory key we have is a local write
Expand All @@ -251,7 +258,7 @@ Gun.ask = require('./ask');
tmp = keys.length;
console.STAT && console.STAT(S, -(S - (S = +new Date)), 'got copied some');
DBG && (DBG.ga = +new Date);
root.on('in', {'@': to, '#': id, put: put, '%': (tmp? (id = text_rand(9)) : u), $: root.$, _: faith, DBG: DBG});
root.on('in', {'@': to, '#': id, put: put, '%': (tmp? (id = text_rand(9)) : u), $: root.$, _: faith, DBG: DBG, FOO: 1});
console.STAT && console.STAT(S, +new Date - S, 'got in');
if(!tmp){ return }
setTimeout.turn(go);
Expand Down
4 changes: 2 additions & 2 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4001,7 +4001,7 @@ describe('Gun', function(){
}
return false;
} else {
console.warn('filter should be an Array');
console.warn('Filter should be an Array');
return false;
}
}
Expand Down Expand Up @@ -7490,7 +7490,7 @@ describe('Gun', function(){
return cb.call(gun, null, data);
}, opt);
} else {
//console.Log("Warning! You have no persistence layer to save to!");
//console.warn("You have no persistence layer to save to!");
cb.call(gun, null); // This is in memory success, hardly "success" at all.
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/panic/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("Stress test GUN with SEA users causing PANIC!", function(){
// As a result, we have to manually pass it scope.
test.async();
// Clean up from previous test.
try{ require('fs').unlinkSync(env.i+'data') }catch(e){ console.log("!!! WARNING !!!! MUST MANUALLY REMOVE OLD DATA!!!!, e") }
try{ require('fs').unlinkSync(env.i+'data') }catch(e){ console.warn("MUST MANUALLY REMOVE OLD DATA!!!!, e") }
var purl = 'https://'+env.config.IP+':'+env.config.port;
require('gun/test/https/test')(env.config.port + env.i, env.i+'data', function(){
// This server peer is now done with the test!
Expand Down
2 changes: 1 addition & 1 deletion test/panic/speak.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("Stress test GUN with SEA users causing PANIC!", function(){
test.async();
//setInterval(function(){ var u, t; u = process.memoryUsage().heapUsed; t = require('os').totalmem(); console.log((u/t).toFixed(2)) }, 1000)
// Clean up from previous test.
try{ require('fs').unlinkSync(env.i+'data') }catch(e){ console.log("!!! WARNING !!!! MUST MANUALLY REMOVE OLD DATA!!!!, e") }
try{ require('fs').unlinkSync(env.i+'data') }catch(e){ console.warn("MUST MANUALLY REMOVE OLD DATA!!!!, e") }
var purl = 'https://'+env.config.IP+':'+env.config.port;
require('gun/test/https/test')(env.config.port + env.i, env.i+'data', function(){
// This server peer is now done with the test!
Expand Down
2 changes: 1 addition & 1 deletion test/sea/sea.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('SEA', function(){
indexedDB.deleteDatabase('radatatest').onsuccess = function(e){ done() }
});
/*it('generates aeskey from jwk', function(done) { // DEPRECATED!!!
console.log("WARNING: THIS DOES NOT WORK IN BROWSER!!!! NEEDS FIX");
console.warn("THIS DOES NOT WORK IN BROWSER!!!! NEEDS FIX");
SEA.opt.aeskey('x','x').then(k => {
//console.log("DATA", k.data);
expect(k.data.toString('base64')).to.be('Xd6JaIf2dUybFb/jpEGuSAbfL96UABMR4IvxEGIuC74=')
Expand Down
2 changes: 1 addition & 1 deletion test/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Trace.log = function(evname, msg) {
// Trace.on('trace.end', {code: Trace.traces.join('\n')});
// }, 1000);
if (!msg) {
//console.log('WARN, empty message: ',msg);
//console.warn('Empty message: ',msg);
// msg=evname;
// evname = 'GUN';
}
Expand Down

0 comments on commit cc38e51

Please sign in to comment.