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

chore: improve error message for invalid ipfs paths #51

Merged
merged 2 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions path.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// A Path represents an ipfs content path:
// * /<cid>/path/to/file
// * <cid>/path/to/file
// * /ipfs/<cid>
// * /ipns/<cid>/path/to/folder
// * etc
Expand Down Expand Up @@ -104,7 +104,7 @@ func ParsePath(txt string) (Path, error) {
}

if len(parts) < 3 {
return "", &pathError{error: fmt.Errorf("path does not begin with '/'"), path: txt}
return "", &pathError{error: fmt.Errorf("invalid ipfs path"), path: txt}
}

//TODO: make this smarter
Expand Down
13 changes: 13 additions & 0 deletions path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ func TestNoComponents(t *testing.T) {
}
}

func TestInvalidPaths(t *testing.T) {
for _, s := range []string{
"/ipfs",
"/testfs",
"/",
} {
_, err := ParsePath(s)
if err == nil || !strings.Contains(err.Error(), "invalid ipfs path") || !strings.Contains(err.Error(), s) {
t.Error("wrong error")
}
}
}

func TestIsJustAKey(t *testing.T) {
cases := map[string]bool{
"QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": true,
Expand Down