Skip to content

Commit b7ab837

Browse files
committed
fix: improve error reporting for trustless gateways
Include more information in the thrown errors and allow identifying individual gateways on stringification.
1 parent 027bd35 commit b7ab837

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/block-brokers/src/trustless-gateway/trustless-gateway.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class TrustlessGateway {
141141
this.log('GET %s %d', gwUrl, res.status)
142142
if (!res.ok) {
143143
this.#errors++
144-
throw new Error(`unable to fetch raw block for CID ${cid} from gateway ${this.url}`)
144+
throw new Error(`Unable to fetch raw block for CID ${cid} from gateway ${this.url}, recieved ${res.status} ${res.statusText}`)
145145
}
146146
// limited Response ensures the body is less than 2MiB (or configurable maxSize)
147147
// see https://github.com/ipfs/helia/issues/790
@@ -152,14 +152,14 @@ export class TrustlessGateway {
152152
this.#pendingResponses.set(blockId, pendingResponse)
153153
}
154154
return await pendingResponse
155-
} catch (cause) {
155+
} catch (cause: any) {
156156
// @ts-expect-error - TS thinks signal?.aborted can only be false now
157157
// because it was checked for true above.
158158
if (signal?.aborted === true) {
159-
throw new Error(`fetching raw block for CID ${cid} from gateway ${this.url} was aborted`)
159+
throw new Error(`Fetching raw block for CID ${cid} from gateway ${this.url} was aborted`)
160160
}
161161
this.#errors++
162-
throw new Error(`unable to fetch raw block for CID ${cid}`)
162+
throw new Error(`Unable to fetch raw block for CID ${cid} - ` + cause.message)
163163
} finally {
164164
signal?.removeEventListener('abort', abortInnerSignal)
165165
this.#pendingResponses.delete(blockId)
@@ -215,4 +215,8 @@ export class TrustlessGateway {
215215
pendingResponses: this.#pendingResponses.size
216216
}
217217
}
218+
219+
toString (): string {
220+
return `TrustlessGateway(${this.url})`
221+
}
218222
}

packages/utils/src/abstract-session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export abstract class AbstractSession<Provider, RetrieveBlockProgressEvents exte
100100
concurrency: this.maxProviders
101101
})
102102
queue.addEventListener('failure', (evt) => {
103-
this.log.error('error querying provider %o, evicting from session', evt.detail.job.options.provider, evt.detail.error)
103+
this.log.error('error querying provider %s, evicting from session - %e', evt.detail.job.options.provider, evt.detail.error)
104104
this.evict(evt.detail.job.options.provider)
105105
})
106106
queue.addEventListener('success', (evt) => {

0 commit comments

Comments
 (0)