Skip to content

Commit

Permalink
Merge pull request #11454 from janisz/fix_extract_error
Browse files Browse the repository at this point in the history
bug: return error on invalid function name in extract.TranslatableStrings
  • Loading branch information
sharifelgamal authored Jun 2, 2021
2 parents 45ee2db + 7e05765 commit 47dbbd5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/minikube/extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func newExtractor(functionsToCheck []string) (*state, error) {
// Functions must be of the form "package.function"
t2 := strings.Split(t, ".")
if len(t2) < 2 {
return nil, errors.Wrap(nil, fmt.Sprintf("Invalid function string %s. Needs package name as well.", t))
return nil, errors.Errorf("invalid function string %s. Needs package name as well", t)
}
f := funcType{
pack: t2[0],
Expand Down
10 changes: 10 additions & 0 deletions pkg/minikube/extract/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package extract

import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -84,3 +85,12 @@ func TestExtract(t *testing.T) {
}

}

func TestExtractShouldReturnErrorOnFunctionWithoutPackage(t *testing.T) {
expected := errors.New("Initializing: invalid function string missing_package. Needs package name as well")
funcs := []string{"missing_package"}
err := TranslatableStrings([]string{}, funcs, "")
if err == nil || err.Error() != expected.Error() {
t.Fatalf("expected %v, got %v", expected, err)
}
}

0 comments on commit 47dbbd5

Please sign in to comment.