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

Commit 6a7cf29

Browse files
authored
fix: skip downloading CIDs for empty files (#617)
Some CIDs represent an empty file and Storacha returns HTTP 410 Gone error response in such case. In this patch, I am fixing the function `fetchMeasurements` to skip the retrieval and return an empty list for such CIDs. Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
1 parent 4bf1228 commit 6a7cf29

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/preprocess.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ export const preprocess = async ({
156156
* @returns {Promise<import('./typings.js').RawMeasurement[]>}
157157
*/
158158
export const fetchMeasurements = async (cid, { signal, noCache = false } = {}) => {
159+
if (cid === 'bafkqaaa' || cid === 'bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku') {
160+
// These CIDs represent an empty file
161+
return []
162+
}
163+
159164
const res = await fetch(
160165
`https://${encodeURIComponent(cid)}.ipfs.w3s.link?format=car`,
161166
{

test/preprocess.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
preprocess,
55
Measurement,
66
parseMeasurements,
7-
assertValidMeasurement
7+
assertValidMeasurement,
8+
fetchMeasurements
89
} from '../lib/preprocess.js'
910
import { Point } from '../lib/telemetry.js'
1011
import assert from 'node:assert'
@@ -86,6 +87,20 @@ describe('preprocess', () => {
8687
})
8788
})
8889

90+
describe('fetchMeasurements', () => {
91+
it('handles empty batch with CID bafkqaaa', async () => {
92+
const cid = 'bafkqaaa'
93+
const measurements = await fetchMeasurements(cid)
94+
assert.deepStrictEqual(measurements, [])
95+
})
96+
97+
it('handles empty batch with CID bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku', async () => {
98+
const cid = 'bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'
99+
const measurements = await fetchMeasurements(cid)
100+
assert.deepStrictEqual(measurements, [])
101+
})
102+
})
103+
89104
describe('parseMeasurements', () => {
90105
const measurements = [{ foo: 'bar' }, { beep: 'boop' }]
91106
it('parses a JSON array', () => {

0 commit comments

Comments
 (0)