Skip to content

Commit bfd65ae

Browse files
authored
refactor typed-error-describe (#3111)
1 parent d38dc6b commit bfd65ae

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

cmd/describe.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
fn "knative.dev/func/pkg/functions"
1717
)
1818

19+
var ErrNameAndPathConflict = errors.New("cannot specify both name and path")
20+
1921
func NewDescribeCmd(newClient ClientFactory) *cobra.Command {
2022
cmd := &cobra.Command{
2123
Use: "describe <name>",
@@ -128,7 +130,7 @@ func newDescribeConfig(cmd *cobra.Command, args []string) (cfg describeConfig, e
128130
// logically inconsistent to provide both a name and a path to source.
129131
// Either use the function's local state on disk (--path), or specify
130132
// a name and a namespace to ignore any local function source.
131-
err = fmt.Errorf("only one of --path and [NAME] should be provided")
133+
err = ErrNameAndPathConflict
132134
}
133135
return
134136
}

cmd/describe_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"context"
5+
"errors"
56
"strings"
67
"testing"
78

@@ -126,8 +127,9 @@ func TestDescribe_NameAndPathExclusivity(t *testing.T) {
126127
cmd := NewDescribeCmd(NewTestClient(fn.WithDescriber(d)))
127128
cmd.SetArgs([]string{"-p", "./testpath", "testname"})
128129
if err := cmd.Execute(); err == nil {
129-
// TODO(lkingland): use a typed error
130130
t.Fatalf("expected error on conflicting flags not received")
131+
} else if !errors.Is(err, ErrNameAndPathConflict) {
132+
t.Fatalf("expected ErrNameAndPathExclusivity, got %v", err)
131133
}
132134
if d.DescribeInvoked {
133135
t.Fatal("describer was invoked when conflicting flags were provided")

0 commit comments

Comments
 (0)