From 5f6a39145d9ac109d430190d0d352544d27b6561 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Mon, 21 Dec 2020 11:04:17 +0100 Subject: entity: add error to signal invalid format --- entity/err.go | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'entity/err.go') diff --git a/entity/err.go b/entity/err.go index 90304d03..9222e4da 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 NewErrUnknowFormat(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, expected 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) } -- cgit From d0d7be8db010e2c68c98d0a34387e4fac0c4d6ee Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 14 Feb 2021 12:14:03 +0100 Subject: minor cleanups --- entity/err.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'entity/err.go') diff --git a/entity/err.go b/entity/err.go index 9222e4da..9f7f5a1a 100644 --- a/entity/err.go +++ b/entity/err.go @@ -52,7 +52,7 @@ func NewErrUnknowFormat(expected uint) *ErrInvalidFormat { func (e ErrInvalidFormat) Error() string { if e.version == 0 { - return fmt.Sprintf("unreadable data, expected format version %v", e.expected) + 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) -- cgit From 1ced77af1a4bdbaa212a74bf0c56b2b81cdc5bd2 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 14 Feb 2021 12:24:40 +0100 Subject: fix merge --- entity/err.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'entity/err.go') diff --git a/entity/err.go b/entity/err.go index 9f7f5a1a..408e27b4 100644 --- a/entity/err.go +++ b/entity/err.go @@ -43,7 +43,7 @@ func NewErrInvalidFormat(version uint, expected uint) *ErrInvalidFormat { } } -func NewErrUnknowFormat(expected uint) *ErrInvalidFormat { +func NewErrUnknownFormat(expected uint) *ErrInvalidFormat { return &ErrInvalidFormat{ version: 0, expected: expected, -- cgit