Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.

Commit 2e47236

Browse files
authored
fix: improve logs (#73)
Example output before my change: ``` Retrieval failed with status code 502: no candidates found { timeout: false, startAt: 2024-05-31T07:30:43.389Z, // etc. protocol: "graphsync", providerAddress: "/ip4/118.212.68.22/tcp/24501/p2p/12D3KooWJJEL214g7yMFMFaE6aPRaQTLVVCNFjWeiBLUCTzP98tp" } Submitting measurement... { sparkVersion: "1.11.4", zinniaVersion: "0.19.1", cid: "bafykbzacechhbxnsn5dw6lx7phcfvkjc6kqsuuwl4bnynexewb5y3vtcw2fvw", minerId: "f02894875", timeout: false, startAt: 2024-05-31T07:30:43.389Z, // etc. providerAddress: "/ip4/118.212.68.22/tcp/24501/p2p/12D3KooWJJEL214g7yMFMFaE6aPRaQTLVVCNFjWeiBLUCTzP98tp", participantAddress: "0x000000000000000000000000000000000000dEaD", stationId: "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } ``` This commit removes the first log which was printed when `fetch()` was able to get some HTTP response frome the server. It is also removing the trailing newline from HTTP error response bodies before we print them to the console. Finally, it adds an empty line between tasks, to visually delimit logs belonging to different tasks.
1 parent c7fde0a commit 2e47236

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

lib/ipni-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export async function queryTheIndex (cid, providerId) {
1616
try {
1717
const res = await fetch(url)
1818
if (!res.ok) {
19-
console.error('IPNI query failed, HTTP response: %s %s', res.status, await res.text())
19+
console.error('IPNI query failed, HTTP response: %s %s', res.status, (await res.text()).trimEnd())
2020
return { indexerResult: `ERROR_${res.status}` }
2121
}
2222

lib/miner-info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function rpc (method, ...params) {
3636
const res = await fetch(req)
3737

3838
if (!res.ok) {
39-
throw new Error(`JSON RPC failed with ${res.code}: ${await res.text()}`)
39+
throw new Error(`JSON RPC failed with ${res.code}: ${(await res.text()).trimEnd()}`)
4040
}
4141

4242
const body = await res.json()

lib/spark.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,13 @@ export default class Spark {
153153
}
154154
} else {
155155
console.error('Retrieval failed with status code %s: %s',
156-
res.status, await res.text())
156+
res.status, (await res.text()).trimEnd())
157157
}
158158
} finally {
159159
clearTimeout(timeout)
160160
}
161161

162162
stats.endAt = new Date()
163-
console.log(stats)
164163
}
165164

166165
async submitMeasurement (task, stats) {
@@ -226,6 +225,7 @@ export default class Spark {
226225
if (delay > 0) {
227226
console.log('Sleeping for %s seconds before starting the next task...', Math.round(delay / 1000))
228227
await sleep(delay)
228+
console.log() // add an empty line to visually delimit logs from different tasks
229229
}
230230
}
231231
}
@@ -247,7 +247,7 @@ async function assertOkResponse (res, errorMsg) {
247247
try {
248248
body = await res.text()
249249
} catch {}
250-
const err = new Error(`${errorMsg ?? 'Fetch failed'} (${res.status}): ${body}`)
250+
const err = new Error(`${errorMsg ?? 'Fetch failed'} (${res.status}): ${body.trimEnd()}`)
251251
err.statusCode = res.status
252252
err.serverMessage = body
253253
throw err

manual-check.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ const minerId = 'f010479'
1313
const spark = new Spark()
1414
const stats = { cid, minerId, indexerResult: null, statusCode: null, byteLength: 0 }
1515
await spark.executeRetrievalCheck({ cid, minerId }, stats)
16+
console.log('Measurement: %o', stats)

0 commit comments

Comments
 (0)