Skip to content

Commit

Permalink
remove console logs, make sure rejections include Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Mar 17, 2024
1 parent 26829df commit c8a0755
Show file tree
Hide file tree
Showing 16 changed files with 12 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/controlflow/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nostrwatch/controlflow",
"version": "0.2.0",
"version": "0.2.1",
"description": "Provides exports for application control flow",
"main": "index.js",
"type": "module",
Expand Down
1 change: 0 additions & 1 deletion packages/controlflow/src/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class Scheduler {
const totalInterval = this.workers.reduce((sum, worker) => sum + worker.interval, 0);
let cumulativeOffset = 0;
this.workers.forEach(worker => {
// console.log(worker)
this.analysis[worker.name] = {
interval: worker.interval,
offset: this.calculateBestOffset(worker, cumulativeOffset, totalInterval),
Expand Down
2 changes: 1 addition & 1 deletion packages/nocap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nostrwatch/nocap",
"version": "0.4.2",
"version": "0.4.3",
"main": "src/index.js",
"type": "module",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/nocap/src/classes/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class Base {
return this.check([keys])

if( !(keys instanceof Array) || !keys.length)
return this.throw(`check(${keys}) failed. keys must be one (string) or several (array of strings).`)
return this.throw(new Error(`check(${keys}) failed. keys must be one (string) or several (array of strings).`))

this.checksRequested = keys
this.evaluate_requested_checks()
Expand Down
1 change: 0 additions & 1 deletion packages/nocap/src/classes/Validator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export class Validator {
validate(key, value){
// console.log(this)
if(typeof this?.defaults?.[key] === 'undefined')
throw new Error(`${this.constructor.name} does not have property '${key}'`)
if(value && typeof this.defaults[key] !== typeof value)
Expand Down
6 changes: 1 addition & 5 deletions packages/nwcache/migrations/normalize_relay_urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ const chunkArray = function(arr, chunkSize) {
console.log(relaydb.relay.count.all())
const relays = await relaydb.relay.get.all()

const chunks = chunkArray(relays, 100)

// console.log(chunks)
// process.exit()

const chunks = chunkArray(relays, 100)

let count = 0
for(const chunk of chunks){
Expand Down
1 change: 0 additions & 1 deletion packages/nwcache/mixins/checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default class CheckMixin {
}

validate(RelayObj){
// console.log(RelayObj)
if(!RelayObj?.url)
throw new Error("Relay object must have a url property")
}
Expand Down
1 change: 0 additions & 1 deletion packages/nwcache/mixins/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ const relay_get = (db) => {
const paymentRequired = db.check.info.get.all().filter( rci => rci?.data?.limitation && rci?.data?.limitation?.payment_required && rci.data.limitation.payment_required === true ).map( res => [ res.relay_id, res['#'] ] )
const relayIds = paymentRequired.map( r => r[0] )
const relayInfoIds = paymentRequired.map( r => r[1] )
console.log('ids', relayIds)
let relays = this.many(relayIds)
relays = relays.filter( relay => relay.info.ref )

Expand Down
2 changes: 1 addition & 1 deletion packages/nwcache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nostrwatch/nwcache",
"version": "0.1.0",
"version": "0.1.1",
"type": "module",
"main": "index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/publisher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nostrwatch/publisher",
"version": "0.4.0",
"version": "0.4.1",
"type": "module",
"description": "Library for publishing nostr.watch relay status and publisher registration events",
"main": "index.js",
Expand Down
11 changes: 2 additions & 9 deletions packages/publisher/src/Publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ async function writeObjectToFile(obj) {

try {
await fs.writeFile(fileName, jsonContent);
// console.log(`File ${fileName} has been written.`);
} catch (error) {
console.error('Error writing file:', error);
}
Expand Down Expand Up @@ -79,12 +78,9 @@ export class Publisher {
signEvent(event){
event.id = getEventHash(event)
event.sig = getSignature(event, process.env.DAEMON_PRIVKEY || "")
// console.log('++signedEvent')
// console.dir(event)
const valid = validateEvent(event) && verifySignature(event)
if(!valid)
throw new Error('generateEvent(): event does not validate')
// if(signedEvent.tags.filter( tag => tag[0]==='s' && tag[1]==='online' ).length > 0) console.log(signedEvent)
return event
}

Expand All @@ -98,13 +94,10 @@ export class Publisher {

async publishEvent(signedEvent){
// writeObjectToFile(signedEvent);
console.log
const pool = new SimplePool();
const relays = config.publisher.to_relays
let pubs = pool.publish(relays, signedEvent)
await Promise.all( pubs ).catch(console.error)
// console.log(pubs)
// process.exit()
await Promise.all( pubs ).catch( e => { log.error(`publishEvent(): Error: ${e}`) })
return Promise.all( pubs )
}

Expand Down Expand Up @@ -137,7 +130,7 @@ export class PublisherNocap extends Publisher {
const unsignedEvent = this.generateEvent(relay)
signedEvents.push(this.signEvent(unsignedEvent))
}
await this.publishEvents(signedEvents).catch(console.error)
await this.publishEvents(signedEvents).catch( e => { log.error(`PublisherNocap::many(): Error: ${e}`) })
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/publisher/src/kinds/Kind0.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Kind0 extends Publisher {
content = JSON.stringify(data)
}
catch(e){
console.dir(data)
console.dir(`Kind0::generateContent(): Error: ${e}`)
throw new Error('Was not able to stringify data for kind 0 content field.')
}
return content
Expand Down
4 changes: 1 addition & 3 deletions packages/seed/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export const bootstrap = async (caller) => {
api = emptyResponse(),
events = emptyResponse()

// console.log(opts.sources, opts.sources.includes('api'))

if(opts.sources.includes('config'))
configseed = [ config?.seed, Date.now() ]

Expand Down Expand Up @@ -101,7 +99,7 @@ export const relaysFromStaticSeed = async (opts) => {
const data = yaml.load(fileContents);
return data?.relays? [ data.relays, Date.now() ]: emptyResponse() //update Date to reflect modification date of seed file.
} catch (e) {
console.error(e);
logger.err(e);
return emptyResponse()
}
}
Expand Down
3 changes: 0 additions & 3 deletions packages/seed/src/nwcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import config from './config.js'

let $rcache

console.log(process.env.PWD, process.cwd())
console.log('config', config)

if(!config?.cache_path)
throw new Error("No LMDB path specified in config")

Expand Down
3 changes: 1 addition & 2 deletions packages/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ export const loadConfigSync = function() {
const fileContents = fs.readFileSync(configPath, 'utf8');
return yaml.load(fileContents);
} catch (e) {
console.error(e);
console.error("loadConfigSync Error: ", e);
throw new Error('config.yaml not found')
}
};

export const loadConfig = async function() {
const handle_error = (e) => {
// console.error(e);
return new Error('config.yaml not found')
}
const configPath = process.env.CONFIG_PATH || './config.yaml';
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nostrwatch/utils",
"version": "0.1.0",
"version": "0.1.2",
"type": "module",
"main": "index.js",
"license": "MIT",
Expand Down

0 comments on commit c8a0755

Please sign in to comment.