From 0fd93603f074f716d09e52eccbe2b78cc77baeea Mon Sep 17 00:00:00 2001 From: Haochen Tong Date: Wed, 19 Apr 2023 19:01:18 +0800 Subject: [PATCH] Do not return hard error on unparsable version --- conn_http.go | 5 +---- lib/proto/handshake.go | 13 +++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/conn_http.go b/conn_http.go index b0095c5128..9bb47d9e44 100644 --- a/conn_http.go +++ b/conn_http.go @@ -292,10 +292,7 @@ func (h *httpConnect) readVersion(ctx context.Context) (proto.Version, error) { for rows.Next() { var v string rows.Scan(&v) - version, err := proto.ParseVersion(v) - if err != nil { - return proto.Version{}, err - } + version := proto.ParseVersion(v) return version, nil } return proto.Version{}, errors.New("unable to determine version") diff --git a/lib/proto/handshake.go b/lib/proto/handshake.go index 72b51e6028..6ee620905c 100644 --- a/lib/proto/handshake.go +++ b/lib/proto/handshake.go @@ -60,21 +60,22 @@ type Version struct { Patch uint64 } -func ParseVersion(v string) (ver Version, err error) { +func ParseVersion(v string) (ver Version) { + var err error parts := strings.Split(v, ".") if len(parts) < 3 { - return Version{}, fmt.Errorf("%s is not a valid version", v) + return ver } if ver.Major, err = strconv.ParseUint(parts[0], 10, 8); err != nil { - return Version{}, err + return ver } if ver.Minor, err = strconv.ParseUint(parts[1], 10, 8); err != nil { - return Version{}, err + return ver } if ver.Patch, err = strconv.ParseUint(parts[2], 10, 8); err != nil { - return Version{}, err + return ver } - return ver, nil + return ver } func CheckMinVersion(constraint Version, version Version) bool {