Skip to content

Commit 2f9cbaa

Browse files
committed
fix: return error on invalid function name
> Wrap returns an error annotating err with a stack trace at the point Wrap is called, and the supplied message. If err is nil, Wrap returns nil. https://pkg.go.dev/github.com/pkg/errors#Wrap
1 parent 4f345f2 commit 2f9cbaa

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pkg/minikube/extract/extract.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func newExtractor(functionsToCheck []string) (*state, error) {
9191
// Functions must be of the form "package.function"
9292
t2 := strings.Split(t, ".")
9393
if len(t2) < 2 {
94-
return nil, errors.Wrap(nil, fmt.Sprintf("Invalid function string %s. Needs package name as well.", t))
94+
return nil, errors.Errorf("Invalid function string %s. Needs package name as well.", t)
9595
}
9696
f := funcType{
9797
pack: t2[0],

pkg/minikube/extract/extract_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package extract
1818

1919
import (
2020
"encoding/json"
21+
"errors"
2122
"io/ioutil"
2223
"os"
2324
"path/filepath"
@@ -84,3 +85,12 @@ func TestExtract(t *testing.T) {
8485
}
8586

8687
}
88+
89+
func TestExtractShouldReturnErrorOnFunctionWithoutPackage(t *testing.T) {
90+
expected := errors.New("Initializing: Invalid function string missing_package. Needs package name as well.")
91+
funcs := []string{"missing_package"}
92+
err := TranslatableStrings([]string{}, funcs, "")
93+
if err == nil || err.Error() != expected.Error() {
94+
t.Fatalf("expected %v, got %v", expected, err)
95+
}
96+
}

0 commit comments

Comments
 (0)