From 9f50a9e58d39065229b33a3ef83fb6af1afa7121 Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Fri, 24 Nov 2023 11:46:36 +0100 Subject: [PATCH] semver: Error instead of crash on no argument --- internal/filter/semver/semver.go | 4 ++++ internal/pipeline/testdata/semver | 3 +++ 2 files changed, 7 insertions(+) diff --git a/internal/filter/semver/semver.go b/internal/filter/semver/semver.go index 9345685..313046a 100644 --- a/internal/filter/semver/semver.go +++ b/internal/filter/semver/semver.go @@ -1,6 +1,7 @@ package semver import ( + "fmt" "regexp" "sort" "strconv" @@ -71,6 +72,9 @@ func New(prefix string, arg string) (filter filter.Filter, err error) { if prefix != Name && prefix != "" { return nil, nil } + if arg == "" { + return nil, fmt.Errorf("needs a contraint or version pattern argument") + } constraint, err = mmsemver.NewConstraint(arg) if prefix == Name { diff --git a/internal/pipeline/testdata/semver b/internal/pipeline/testdata/semver index bebc8ba..43c05cc 100644 --- a/internal/pipeline/testdata/semver +++ b/internal/pipeline/testdata/semver @@ -22,3 +22,6 @@ semver:vn.n.n.n -> semver:vn.n.n.n n -> error:no filter matches n. -> error:no filter matches + +semver -> error:no filter matches +semver: -> error:needs a contraint or version pattern argument