Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

fix: improved error message on broken CIDv0 #33

Merged
merged 4 commits into from
Dec 3, 2020
Merged

Conversation

rvagg
Copy link
Member

@rvagg rvagg commented Dec 2, 2020

move @lidel's fix from ipfs/go-cid#116

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @lidel

path.go Outdated
func decodeCid(cstr string) (cid.Cid, error) {
c, err := cid.Decode(cstr)
if err != nil && len(cstr) == 46 && cstr[:2] == "qm" { // https://github.com/ipfs/go-ipfs/issues/7792
return cid.Cid{}, fmt.Errorf("%v: This looks like a CIDv0 that has been lowercased. Convert the CIDv0 to CIDv1 in case-insensitive base32 using 'ipfs cid base32 <Qm..>' and try again.", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still like this to be much shorter. Can we just say "this looks like a lowercase CID"? Telling the user what to do is a bit out of scope for an error.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'This looks like a CIDv0 that has been lowercased; you may wish to convert to case-agnostic CIDv1' or similar? Intent would be not to tell user what to do, but hint that there's a workaround if preserving case isn't an option.

@Stebalien
Copy link
Member

Stebalien commented Dec 2, 2020 via email

@rvagg
Copy link
Member Author

rvagg commented Dec 2, 2020

pushed a fixup with:

This looks like a CIDv0 that has been lowercased; consider converting to a case-agnostic CIDv1, such as base32

How's that sound?

@Stebalien
Copy link
Member

It should start lower case and I'd prefer if it were a bit shorter, but that's not a huge issue.

@rvagg
Copy link
Member Author

rvagg commented Dec 2, 2020

"%v (possible lowercased CIDv0; consider converting to a case-agnostic CIDv1, such as base32)"

how's this for a compromise between size and communicating what's wrong @Stebalien @jessicaschilling?

The construction does get a bit whacky when you look at it in full, which is why I'm trying out the parens:

invalid path "/ipfs/qmbwqxbekc3p8tqskc98xmwnzrzdtrlmimpl8wbutgsmnr": invalid CID: selected encoding not supported (possible lowercased CIDv0; consider converting to a case-agnostic CIDv1, such as base32)

@jessicaschilling
Copy link

SGTM - it's a little awkward but good enough given the constraints.

@Stebalien
Copy link
Member

LGTM! (although the test needs fixing). I generally avoid long error messages as we tend to glue them together.

@rvagg
Copy link
Member Author

rvagg commented Dec 3, 2020

Sorry, I hadn't properly pushed the version I had locally which had it with parens and the test working. I've squashed now and force pushed the single commit, the message is "%v (possible lowercased CIDv0; consider converting to a case-agnostic CIDv1, such as base32)".

I'll take this as approved and merge shortly.

@Stebalien Stebalien merged commit 3e8c1a8 into master Dec 3, 2020
@Stebalien
Copy link
Member

Stebalien commented Dec 3, 2020

too slow 😛

@Stebalien Stebalien deleted the rvagg/bad-cidv0 branch December 3, 2020 17:38
@ipfs ipfs deleted a comment from welcome bot Dec 7, 2020
@lidel
Copy link
Member

lidel commented Jan 7, 2021

@Stebalien @aschmahmann would it be ok to make a go-path release with this?
I'd love to sneak this into go-ipfs 0.8.0 (ipfs/kubo#7807)

@aschmahmann
Copy link
Contributor

@lidel SGTM

@aschmahmann aschmahmann mentioned this pull request Feb 18, 2021
73 tasks
Jorropo pushed a commit to ipfs/go-libipfs-rapide that referenced this pull request Mar 23, 2023
fix: improved error message on broken CIDv0

This commit was moved from ipfs/go-path@3e8c1a8
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants