Skip to content
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

cmd: validate repo/api file and print nicer error message #3219

Merged
merged 1 commit into from
Nov 21, 2016

Conversation

Kubuxu
Copy link
Member

@Kubuxu Kubuxu commented Sep 13, 2016

Resolves #3191
License: MIT
Signed-off-by: Jakub Sztandera kubuxu@protonmail.ch

@Kubuxu Kubuxu added status/in-progress In progress need/review Needs a review and removed status/in-progress In progress labels Sep 13, 2016
if apiAddrStr == "" {
var err error
if apiAddrStr, err = fsrepo.APIAddr(repoPath); err != nil {
efmt := fmt.Sprintf("failed to parse %[1]s/api file.\n\terror: %%s\n"+
Copy link
Member

Choose a reason for hiding this comment

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

lets make this a multiline string constant somewhere

@Kubuxu
Copy link
Member Author

Kubuxu commented Sep 13, 2016

Updated

@Kubuxu
Copy link
Member Author

Kubuxu commented Sep 13, 2016

Updated once more.

error: %[2]s
If there is no daemon running, it is safe to delete it.
You can do it with:
ps aux | grep ipfs # check there is no ipfs daemon
Copy link
Member

Choose a reason for hiding this comment

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

Not valid advice for windows... not sure what the best way to do this is.

cc @jbenet @lgierth

Copy link
Contributor

@djdv djdv Sep 18, 2016

Choose a reason for hiding this comment

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

On Windows that would be tasklist | findstr ipfs, alternatively you can refer people to the Task Manager.

Copy link

Choose a reason for hiding this comment

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

thanks @djdv, I think something like this works:

If you're sure go-ipfs isn't running, you can just delete it.
Otherwise check:
    ps aux | grep ipfs # on Linux and OSX
    tasklist | findstr ipfs # on Windows

Copy link
Member

Choose a reason for hiding this comment

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

We can also generate this message in an init function where we can do a switch on runtime.GOOS

}

s := string(buf[:n])
s = strings.TrimSpace(s)
return s, nil
m, err := ma.NewMultiaddr(s)
Copy link
Member

Choose a reason for hiding this comment

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

should just return ma.NewMultiaddr(s) here

@whyrusleeping
Copy link
Member

@Kubuxu status update?

@Kubuxu
Copy link
Member Author

Kubuxu commented Sep 30, 2016

I remember looking for a lib that we have already imported that included helpers for checking OSes, and then I did something else.

@Kubuxu Kubuxu added need/author-input Needs input from the original author and removed need/review Needs a review labels Sep 30, 2016
@Kubuxu Kubuxu self-assigned this Sep 30, 2016
@Kubuxu Kubuxu force-pushed the fix/api-file-bad branch 2 times, most recently from a38e5cd to c4542cc Compare October 3, 2016 15:55
@Kubuxu Kubuxu added need/review Needs a review and removed need/author-input Needs input from the original author labels Oct 3, 2016
@Kubuxu
Copy link
Member Author

Kubuxu commented Oct 3, 2016

Updated

@Kubuxu Kubuxu removed their assignment Oct 3, 2016
Copy link
Member

@whyrusleeping whyrusleeping left a comment

Choose a reason for hiding this comment

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

A couple comments, then LGTM

return nil, fmt.Errorf(apiErrorFmt, repoPath, err.Error())
}
}
if len(addr.Protocols()) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Will this ever happen from a passed in apiAddrStr? We don't want to accidentally tell the user about an api file if theyre manually specifying the address

Copy link
Member Author

Choose a reason for hiding this comment

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

This happens when for some reason the API File is empty.

Copy link
Member

Choose a reason for hiding this comment

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

Right, But theres no possible way we can end up with that scenario if the user passes in an api addr with --api right?

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea that is why I added check in 7512eb9

@@ -32,7 +25,14 @@ import (
repo "github.com/ipfs/go-ipfs/repo"
config "github.com/ipfs/go-ipfs/repo/config"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"

logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
"gx/ipfs/QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93/go-os-helper"
Copy link
Member

Choose a reason for hiding this comment

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

since the package name and the directory name arent the same, lets add osh to name this import.

@Kubuxu
Copy link
Member Author

Kubuxu commented Oct 4, 2016

Last commit should address it.

@Kubuxu Kubuxu force-pushed the fix/api-file-bad branch 2 times, most recently from 3b89cf4 to 7512eb9 Compare October 4, 2016 16:42
"author": "Kubuxu",
"hash": "QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93",
"name": "go-os-helper",
"version": "0.0.0"
Copy link
Member Author

Choose a reason for hiding this comment

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

oh, look at that

Copy link
Member

Choose a reason for hiding this comment

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

what am i looking at?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, ok, not it is good. Just a second ago GH wasn't showing the bracket that is bellow this line.

@whyrusleeping
Copy link
Member

@Kubuxu wanna rebase this and make sure the tests pass?

@Kubuxu Kubuxu self-assigned this Oct 28, 2016
@Kubuxu Kubuxu removed the need/review Needs a review label Oct 28, 2016
@Kubuxu
Copy link
Member Author

Kubuxu commented Nov 2, 2016

Rebased.

@Kubuxu Kubuxu force-pushed the fix/api-file-bad branch 3 times, most recently from 5865975 to 6068da7 Compare November 4, 2016 11:24
@Kubuxu
Copy link
Member Author

Kubuxu commented Nov 4, 2016

Recreated it from ground 0 (easier than resolving conflicts in import section).

@Kubuxu Kubuxu assigned whyrusleeping and unassigned Kubuxu Nov 4, 2016
License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
@Kubuxu
Copy link
Member Author

Kubuxu commented Nov 21, 2016

@whyrusleeping should be good for merge right now

@Kubuxu Kubuxu added the RFM label Nov 21, 2016
@whyrusleeping whyrusleeping merged commit 9094cc8 into master Nov 21, 2016
@whyrusleeping whyrusleeping deleted the fix/api-file-bad branch November 21, 2016 18:31
@ghost ghost mentioned this pull request Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants