@cryptotaxi247 / kubo / commits / c1b8d292f

repo: clean up migration errors

Improved the repo migration errors to provide instructions to the user.

Juan Batiz-Benet committed Apr 19, 2015 at 14:43 UTC c1b8d292fb8dacf9a8685af675a1baa9e0b5c2d4
1 file changed +15 -5
repo/fsrepo/fsrepo.go
+15 -5
@@ -31,9 +31,19 @@ import (
31 // version number that we are currently expecting to see
32 var RepoVersion = "2"
33
34 -var incorrectRepoFormat = "Repo has incorrect version: '%s'\nProgram version is: '%s'\nPlease run the appropriate migration tool before continuing"
34 +var migrationInstructions = `See https://github.com/ipfs/fs-repo-migrations/blob/master/run.md
35 +Sorry for the inconvenience. In the future, these will run automatically.`
36
36 -var ErrNoVersion = errors.New("version check failed, no version file found, please run 0-to-1 migration tool.")
37 +var errIncorrectRepoFmt = `Repo has incorrect version: %s
38 +Program version is: %s
39 +Please run the ipfs migration tool before continuing.
40 +` + migrationInstructions
41 +
42 +var (
43 + ErrNoRepo = errors.New("no ipfs repo found. please run: ipfs init")
44 + ErrNoVersion = errors.New("no version file found, please run 0-to-1 migration tool.\n" + migrationInstructions)
45 + ErrOldRepo = errors.New("ipfs repo found in old '~/.go-ipfs' location, please run migration tool.\n" + migrationInstructions)
46 +)
47
48 const (
49 leveldbDirectory = "datastore"
@@ -124,7 +134,7 @@ func open(repoPath string) (repo.Repo, error) {
134 }
135
136 if ver != RepoVersion {
127 - return nil, fmt.Errorf(incorrectRepoFormat, ver, RepoVersion)
137 + return nil, fmt.Errorf(errIncorrectRepoFmt, ver, RepoVersion)
138 }
139
140 // check repo path, then check all constituent parts.
@@ -160,9 +170,9 @@ func checkInitialized(path string) error {
170 if !isInitializedUnsynced(path) {
171 alt := strings.Replace(path, ".ipfs", ".go-ipfs", 1)
172 if isInitializedUnsynced(alt) {
163 - return debugerror.New("ipfs repo found in old '.go-ipfs' location, please run migration tool")
173 + return ErrOldRepo
174 }
165 - return debugerror.New("ipfs not initialized, please run 'ipfs init'")
175 + return ErrNoRepo
176 }
177 return nil
178 }