From 92bb35137becd1f895c6ef4b2ec6fde0c718239b Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Fri, 12 Jul 2019 15:28:26 -0700 Subject: [PATCH] Make sure err_map.go exists --- pkg/minikube/extract/extract.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/minikube/extract/extract.go b/pkg/minikube/extract/extract.go index 5179e4e3c9..e2200125ae 100644 --- a/pkg/minikube/extract/extract.go +++ b/pkg/minikube/extract/extract.go @@ -47,6 +47,8 @@ var blacklist = []string{ "opt %s", } +const ERR_MAP_FILE string = "pkg/minikube/problem/err_map.go" + // state is a struct that represent the current state of the extraction process type state struct { // The list of functions to check for @@ -118,8 +120,11 @@ func TranslatableStrings(paths []string, functions []string, output string) erro } if strings.Contains(cwd, "cmd") { - fmt.Println("Run extract.go from the minikube root directory.") - os.Exit(1) + return errors.New("Run extract.go from the minikube root directory.") + } + + if _, err = os.Stat(ERR_MAP_FILE); os.IsNotExist(err) { + return errors.New("err_map.go doesn't exist.") } e, err := newExtractor(functions) @@ -173,9 +178,8 @@ func inspectFile(e *state) error { return err } - if strings.HasSuffix(e.filename, "err_map.go") { - extractAdvice(file, e) - return nil + if e.filename == ERR_MAP_FILE { + return extractAdvice(file, e) } ast.Inspect(file, func(x ast.Node) bool { @@ -401,7 +405,7 @@ func addParentFuncToList(e *state) { } // extractAdvice specifically extracts Advice strings in err_map.go, since they don't conform to our normal translatable string format. -func extractAdvice(f ast.Node, e *state) { +func extractAdvice(f ast.Node, e *state) error { ast.Inspect(f, func(x ast.Node) bool { // We want the "Advice: " key-value pair // First make sure we're looking at a kvp @@ -423,4 +427,6 @@ func extractAdvice(f ast.Node, e *state) { } return true }) + + return nil }