Skip to content

Commit

Permalink
Use console.warn and 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 4d26c40
Show file tree
Hide file tree
Showing 47 changed files with 149 additions and 132 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 axe.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
tmp = peers[id = 'http://localhost:8765/gun'] = peers[id] || {};
tmp.id = tmp.url = id; tmp.retry = tmp.retry || 0;
Gun.log.once("AXE", "AXE enabled: Trying to find network via (1) local peer (2) last used peers (3) a URL parameter, and last (4) hard coded peers.");
Gun.log.once("AXEWarn", "Warning: AXE is in alpha, use only for testing!");
Gun.warn.once("AXEWarn", "AXE is in alpha, use only for testing!");
var last = lS.peers || ''; if(last){ last += ' ' }
last += ((loc.search||'').split('peers=')[1]||'').split('&')[0];

Expand Down
2 changes: 1 addition & 1 deletion examples/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if (!isElectron && ('serviceWorker' in navigator)) {
navigator.serviceWorker.register('iris/serviceworker.js')
.catch(function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
console.warn('ServiceWorker registration failed: ', err);
});
});
}
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
34 changes: 20 additions & 14 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 @@ -540,7 +540,11 @@
var obj_each = function(o,f){ Object.keys(o).forEach(f,o) }, text_rand = String.random, turn = setTimeout.turn, valid = Gun.valid, state_is = Gun.state.is, state_ify = Gun.state.ify, u, empty = {}, C;

Gun.log = function(){ return (!Gun.log.off && C.log.apply(C, arguments)), [].slice.call(arguments).join(' ') };
Gun.warn = function(){ return (!Gun.log.off && !Gun.warn.off && C.warn.apply(C, arguments)), [].slice.call(arguments).join(' ') };
Gun.error = function(){ return (!Gun.log.off && !Gun.error.off && C.error.apply(C, arguments)), [].slice.call(arguments).join(' ') };
Gun.log.once = function(w,s,o){ return (o = Gun.log.once)[w] = o[w] || 0, o[w]++ || Gun.log(s) };
Gun.warn.once = function(w,s,o){ return (o = Gun.warn.once)[w] = o[w] || 0, o[w]++ || Gun.warn(s) };
Gun.error.once = function(w,s,o){ return (o = Gun.error.once)[w] = o[w] || 0, o[w]++ || Gun.error(s) };

if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window }
try{ if(typeof MODULE !== "undefined"){ MODULE.exports = Gun } }catch(e){}
Expand Down Expand Up @@ -696,7 +700,7 @@
var root = cat.root, gun = msg.$ || (msg.$ = cat.$), at = (gun||'')._ || empty, tmp = msg.put||'', soul = tmp['#'], key = tmp['.'], change = (u !== tmp['='])? tmp['='] : tmp[':'], state = tmp['>'] || -Infinity, sat; // eve = event, at = data at, cat = chain at, sat = sub at (children chains).
if(u !== msg.put && (u === tmp['#'] || u === tmp['.'] || (u === tmp[':'] && u === tmp['=']) || u === tmp['>'])){ // convert from old format
if(!valid(tmp)){
if(!(soul = ((tmp||'')._||'')['#'])){ console.log("chain not yet supported for", tmp, '...', msg, cat); return; }
if(!(soul = ((tmp||'')._||'')['#'])){ console.warn("chain not yet supported for", tmp, '...', msg, cat); return; }
gun = cat.root.$.get(soul);
return setTimeout.each(Object.keys(tmp).sort(), function(k){ // TODO: .keys( is slow // BUG? ?Some re-in logic may depend on this being sync?
if('_' == k || u === (state = state_is(tmp, k))){ return }
Expand Down Expand Up @@ -852,7 +856,7 @@
var gun, tmp;
if(typeof key === 'string'){
if(key.length == 0) {
(gun = this.chain())._.err = {err: Gun.log('0 length key!', key)};
(gun = this.chain())._.err = {err: Gun.warn('0 length key!', key)};
if(cb){ cb.call(gun, gun._.err) }
return gun;
}
Expand Down Expand Up @@ -943,7 +947,7 @@
gun = tmp(this, key);
}
if(!gun){
(gun = this.chain())._.err = {err: Gun.log('Invalid get request!', key)}; // CLEAN UP
(gun = this.chain())._.err = {err: Gun.warn('Invalid get request!', key)}; // CLEAN UP
if(cb){ cb.call(gun, gun._.err) }
return gun;
}
Expand Down Expand Up @@ -1254,7 +1258,7 @@
return gun;
}
function none(gun,opt,chain){
Gun.log.once("valonce", "Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it.");
Gun.warn.once("valonce", "Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it.");
(chain = gun.chain())._.nix = gun.once(function(data, key){ chain._.on('in', this._) });
chain._.lex = gun._.lex; // TODO: Better approach in future? This is quick for now.
return chain;
Expand Down Expand Up @@ -1329,7 +1333,7 @@
gun.on('in', map, chain._);
return chain;
}
Gun.log.once("mapfn", "Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it.");
Gun.warn.once("mapfn", "Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it.");
chain = gun.chain();
gun.map().on(function(data, key, msg, eve){
var next = (cb||noop).call(this, data, key, msg, eve);
Expand Down Expand Up @@ -1366,7 +1370,7 @@
}
gun.put(function(go){
item.get(function(soul, o, msg){ // TODO: BUG! We no longer have this option? & go error not handled?
if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + msg.put + '"!')}) }
if(!soul){ return cb.call(gun, {err: Gun.warn('Only a node can be linked! Not "' + msg.put + '"!')}) }
(tmp = {})[soul] = {'#': soul}; go(tmp);
},true);
})
Expand All @@ -1380,12 +1384,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 +1625,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 +1673,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 @@ -1708,7 +1714,7 @@
if(tmp = console.STAT){ tmp.peers = mesh.near }
if(opt.super){ return } // temporary (?) until we have better fix/solution?
var souls = Object.keys(root.next||''); // TODO: .keys( is slow
if(souls.length > 9999 && !console.SUBS){ console.log(console.SUBS = "Warning: You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`.") }
if(souls.length > 9999 && !console.SUBS){ console.warn(console.SUBS = "You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`.") }
setTimeout.each(souls, function(soul){ var node = root.next[soul];
if(opt.super || (node.ask||'')['']){ mesh.say({get: {'#': soul}}, peer); return }
setTimeout.each(Object.keys(node.ask||''), function(key){ if(!key){ return }
Expand Down Expand Up @@ -1794,7 +1800,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 @@ -1841,7 +1847,7 @@
try{!err && store.setItem(opt.prefix, tmp);
}catch(e){ err = stop = e || "localStorage failure" }
if(err){
Gun.log(err + " Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install");
Gun.error(err + " Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install");
root.on('localStorage:error', {err: err, get: opt.prefix, put: disk});
}
size = tmp.length;
Expand All @@ -1862,7 +1868,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
4 changes: 2 additions & 2 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Gun.on('create', function(root){
fs.readFileSync(opt.file).toString()
: null) || {};

Gun.log.once(
Gun.warn.once(
'file-warning',
'WARNING! This `file.js` module for gun is ' +
'This `file.js` module for gun is ' +
'intended for local development testing only!'
);

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 lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;(function(){
var u;
if(''+u == typeof Gun){ return }
var DEP = function(n){ console.log("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 nts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var smooth = 2;

Gun.on('create', function(root){ // switch to DAM, deprecated old
Gun.log.once("nts", "gun/nts is removed deprecated old");
Gun.warn.once("nts", "gun/nts is removed deprecated old");
this.to.next(root);
return ; // stub out for now. TODO: IMPORTANT! re-add back in later.
var opt = root.opt, mesh = opt.mesh;
Expand Down
Loading

0 comments on commit 4d26c40

Please sign in to comment.