aboutsummaryrefslogtreecommitdiffstats
path: root/entity/err.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2021-04-04 15:49:16 +0200
committerGitHub <noreply@github.com>2021-04-04 15:49:16 +0200
commitfc04af34f5d6dff930003cc1f27ead972d424324 (patch)
tree8b9750d46182fff88d72fcc891e89d5a79ed83b0 /entity/err.go
parent2055bd5d0afb534cc98cd11bd9802d66acbb0c8f (diff)
parentcb9b06551ddc1fae33046733f79ede20f8d09f9a (diff)
downloadgit-bug-fc04af34f5d6dff930003cc1f27ead972d424324.tar.gz
Merge pull request #532 from MichaelMure/dag-entity
Work towards a reusable entity datastructure + commit signature
Diffstat (limited to 'entity/err.go')
-rw-r--r--entity/err.go39
1 files changed, 21 insertions, 18 deletions
diff --git a/entity/err.go b/entity/err.go
index 90304d03..408e27b4 100644
--- a/entity/err.go
+++ b/entity/err.go
@@ -31,28 +31,31 @@ func IsErrMultipleMatch(err error) bool {
return ok
}
-// ErrOldFormatVersion indicate that the read data has a too old format.
-type ErrOldFormatVersion struct {
- formatVersion uint
+type ErrInvalidFormat struct {
+ version uint
+ expected uint
}
-func NewErrOldFormatVersion(formatVersion uint) *ErrOldFormatVersion {
- return &ErrOldFormatVersion{formatVersion: formatVersion}
-}
-
-func (e ErrOldFormatVersion) Error() string {
- return fmt.Sprintf("outdated repository format %v, please use https://github.com/MichaelMure/git-bug-migration to upgrade", e.formatVersion)
-}
-
-// ErrNewFormatVersion indicate that the read data is too new for this software.
-type ErrNewFormatVersion struct {
- formatVersion uint
+func NewErrInvalidFormat(version uint, expected uint) *ErrInvalidFormat {
+ return &ErrInvalidFormat{
+ version: version,
+ expected: expected,
+ }
}
-func NewErrNewFormatVersion(formatVersion uint) *ErrNewFormatVersion {
- return &ErrNewFormatVersion{formatVersion: formatVersion}
+func NewErrUnknownFormat(expected uint) *ErrInvalidFormat {
+ return &ErrInvalidFormat{
+ version: 0,
+ expected: expected,
+ }
}
-func (e ErrNewFormatVersion) Error() string {
- return fmt.Sprintf("your version of git-bug is too old for this repository (version %v), please upgrade to the latest version", e.formatVersion)
+func (e ErrInvalidFormat) Error() string {
+ if e.version == 0 {
+ return fmt.Sprintf("unreadable data, you likely have an outdated repository format, please use https://github.com/MichaelMure/git-bug-migration to upgrade to format version %v", e.expected)
+ }
+ if e.version < e.expected {
+ return fmt.Sprintf("outdated repository format %v, please use https://github.com/MichaelMure/git-bug-migration to upgrade to format version %v", e.version, e.expected)
+ }
+ return fmt.Sprintf("your version of git-bug is too old for this repository (format version %v, expected %v), please upgrade to the latest version", e.version, e.expected)
}