From e3737f216a7b6a36a2ba10146f2d228f32dcbcfb Mon Sep 17 00:00:00 2001 From: vince Date: Thu, 10 Dec 2020 21:12:45 +0800 Subject: expose format version this commit exposes the format version of the operation pack and identity to reduce the changes needed in vendored code when migrating. This also creates error variables that can be propagated and tested against for migrations. --- identity/version.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'identity') diff --git a/identity/version.go b/identity/version.go index 73e4d7c7..bbf93575 100644 --- a/identity/version.go +++ b/identity/version.go @@ -8,6 +8,7 @@ import ( "github.com/pkg/errors" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/lamport" "github.com/MichaelMure/git-bug/util/text" @@ -102,8 +103,11 @@ func (v *Version) UnmarshalJSON(data []byte) error { return err } - if aux.FormatVersion != formatVersion { - return fmt.Errorf("unknown format version %v", aux.FormatVersion) + if aux.FormatVersion < formatVersion { + return entity.NewErrOldFormatVersion(aux.FormatVersion) + } + if aux.FormatVersion > formatVersion { + return entity.NewErrNewFormatVersion(aux.FormatVersion) } v.time = aux.Time -- cgit