fairDataSociety / fdp-storage

Serverless Web3 filesystem for organizing users' personal data implemented in Typescript.

Home Page:https://www.npmjs.com/package/@fairdatasociety/fdp-storage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better error messages needed (when batchId is missing or invalid in this case)

rampall opened this issue · comments

The error messages convey very little to improve dx:

image

@nugaon please triage.

Based on the strack trace it is a BeeJS call const socWriter = connection.bee.makeSOCWriter(privateKey) that does not have anything to do with batchId. It seems the privateKey is incorrect that you passed which is handled by the BeeJS TypeError handling.
can you check whether my assumptions are great and your private key had wrong length (I guess you passed it as a string so it should be 64 characters long hexadecimal characters)

I'm not sure I understand. Afaik there is no privatekey being passed directly as input to any of the public methods provided by FdpStorage class (internally I can understand this might be the case). But this issue is at the FdpStorage class level.
Let me try to explain the issue in another way with two simple scripts:

Script 1

let POSTAGE_BATCH_ID = "" as any 
let fdp = new FdpStorage("http://localhost:1633", POSTAGE_BATCH_ID);
let wallet = fdp.account.createWallet();
let pod = await fdp.personalStorage.create('mypod');
// throws "TypeError: Address not valid hex string of length 64"
// what I meant is that this error says nothing about the four lines of code above that caused it

Script 2

let POSTAGE_BATCH_ID = "fbd57210b7fbc2b96ebfca8631e69cb386dd4cb56b5a75bff32cb627e7df001f" as any
let fdp = new FdpStorage("http://localhost:1633", POSTAGE_BATCH_ID);
let wallet = fdp.account.createWallet();
let pod = await fdp.personalStorage.create('mypod');
// works without error

I know that POSTAGE_BATCH_ID should not be an empty string (I'm overriding that type check with "as any" - for example to import it from a .env variable) like:

let POSTAGE_BATCH_ID = import.meta.env.VITE_POSTAGE_BATCH_ID as any 

Maybe an assertion (instead of reliance on TypeError) to chacth the error earlier somewhere (maybe at the FdpStorage constructor level or such) might be more user friendly?