RangerMauve / hypercore-fetch

Implementation of Fetch that uses the Hyper SDK for loading p2p content
MIT License
36 stars 12 forks source link

Throw error if hyperdrive doesn't exist #57

Closed josephmturner closed 1 year ago

josephmturner commented 1 year ago

Currently, loading a nonexistent hyperdrive returns an empty array. Instead, I think hypercore-fetch should signal an error indicating that the hyperdrive could not be found.

RangerMauve commented 1 year ago

Could elaborate on what "nonexistent" means in this context? Is it a hyperdrive which has no data but which you are accessing via a valid public key?

Would you hope to have an error if there was zero peers found for the drive maybe?

One reason I avoided erroring was that it's hard to tell whether it exists or not just from the initial GET. One might end up finding peers a few seconds later or similar.

josephmturner commented 1 year ago

Would you hope to have an error if there was zero peers found for the drive maybe?

Yes, I think this is what I had in mind.

One reason I avoided erroring was that it's hard to tell whether it exists or not just from the initial GET. One might end up finding peers a few seconds later or similar.

Good point. Could we maybe set a timeout after which hyper-gateway gives up with an error?

RangerMauve commented 1 year ago

Instead of throwing an error, we can detect that the drive is empty by seeing the ETag is 0.

At the moment we try to do a full lookup for peers before returning: https://github.com/RangerMauve/hyper-sdk/blob/master/index.js#L235

So if you get a HEAD and it's ETag is 0, it must be a drive with no peers.

josephmturner commented 1 year ago

It appears that drives with no peers have ETag 1. Is that expected?