-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type-Check CID #365
Type-Check CID #365
Conversation
src/fs/filesystem.ts
Outdated
@@ -164,6 +164,8 @@ export class FileSystem { | |||
* Loads an existing file system from a CID. | |||
*/ | |||
static async fromCID(cid: CID, opts: FileSystemOptions = {}): Promise<FileSystem | null> { | |||
if (!(cid instanceof CID)) throw new Error("Expected a CID object") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry for throwing you into JS/TS land which is horrible :P
instanceof
is dangerous in JS, because if for whatever reason you'll end up with a duplicated copy of the multiformats library in your bundle, their CID
classes are not instanceof
-compatible with each other.
Here's an issue comment that shows the desired pattern to use instead: multiformats/js-cid#111 (comment)
I know, this is an annoyingly small thing and you want to get working on something bigger, it's just for you to get familiar with different parts of our toolchain + code. (Almost done 🎉)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. It's fine. You have been really helpful. 😀
968288f
to
077d983
Compare
077d983
to
697fd9a
Compare
697fd9a
to
3a2d3b1
Compare
e67b4f9
to
e492a0b
Compare
For context and as discussed with @icidasset, the error we get comes from CID being sent via postMessage to a decoding piece that assumes CIDs are of CID class instance (not strings). So the ideal place to do a check is right before the CID is sent since there are other areas in the code that handle a CID multiform nature. |
Can we make this |
Good to go? @icidasset @matheus23 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Summary
This PR implements the following features
cid
s have been updated to use the multiformat-based CID class but old code still use string encoded formats which leads to vague errors. This PR adds a check that returns a clear error message when a cid parameter isn't an object.Closing issues
Fixes #345