Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve logs #73

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ipni-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function queryTheIndex (cid, providerId) {
try {
const res = await fetch(url)
if (!res.ok) {
console.error('IPNI query failed, HTTP response: %s %s', res.status, await res.text())
console.error('IPNI query failed, HTTP response: %s %s', res.status, (await res.text()).trimEnd())
return { indexerResult: `ERROR_${res.status}` }
}

Expand Down
2 changes: 1 addition & 1 deletion lib/miner-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function rpc (method, ...params) {
const res = await fetch(req)

if (!res.ok) {
throw new Error(`JSON RPC failed with ${res.code}: ${await res.text()}`)
throw new Error(`JSON RPC failed with ${res.code}: ${(await res.text()).trimEnd()}`)
}

const body = await res.json()
Expand Down
6 changes: 3 additions & 3 deletions lib/spark.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,13 @@ export default class Spark {
}
} else {
console.error('Retrieval failed with status code %s: %s',
res.status, await res.text())
res.status, (await res.text()).trimEnd())
}
} finally {
clearTimeout(timeout)
}

stats.endAt = new Date()
console.log(stats)
}

async submitMeasurement (task, stats) {
Expand Down Expand Up @@ -226,6 +225,7 @@ export default class Spark {
if (delay > 0) {
console.log('Sleeping for %s seconds before starting the next task...', Math.round(delay / 1000))
await sleep(delay)
console.log() // add an empty line to visually delimit logs from different tasks
}
}
}
Expand All @@ -247,7 +247,7 @@ async function assertOkResponse (res, errorMsg) {
try {
body = await res.text()
} catch {}
const err = new Error(`${errorMsg ?? 'Fetch failed'} (${res.status}): ${body}`)
const err = new Error(`${errorMsg ?? 'Fetch failed'} (${res.status}): ${body.trimEnd()}`)
err.statusCode = res.status
err.serverMessage = body
throw err
Expand Down
1 change: 1 addition & 0 deletions manual-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ const minerId = 'f010479'
const spark = new Spark()
const stats = {}
await spark.executeRetrievalCheck({ cid, minerId }, stats)
console.log('Measurement: %o', stats)