Skip to content

out.FatalT should be followed by non-zero exit #17965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,15 @@ func handleSingleDeletionError(err error) {
if ok {
switch deletionError.Errtype {
case Fatal:
out.FatalT(deletionError.Error())
out.ErrT(style.Fatal, "Failed to delete profile(s): {{.error}}", out.V{"error": deletionError.Error()})
os.Exit(reason.ExGuestError)
case MissingProfile:
out.ErrT(style.Sad, deletionError.Error())
case MissingCluster:
out.ErrT(style.Meh, deletionError.Error())
default:
out.FatalT(deletionError.Error())
out.ErrT(style.Fatal, "Unable to delete profile(s): {{.error}}", out.V{"error": deletionError.Error()})
os.Exit(reason.ExGuestError)
}
} else {
exit.Error(reason.GuestDeletion, "Could not process error from failed deletion", err)
Expand Down
5 changes: 4 additions & 1 deletion cmd/minikube/cmd/node_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package cmd

import (
"os"

"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
Expand Down Expand Up @@ -49,7 +51,8 @@ var nodeStopCmd = &cobra.Command{

err = machine.StopHost(api, machineName)
if err != nil {
out.FatalT("Failed to stop node {{.name}}", out.V{"name": name})
out.ErrT(style.Fatal, "Failed to stop node {{.name}}: {{.error}}", out.V{"name": name, "error": err})
os.Exit(reason.ExHostError)
}
out.Step(style.Stopped, "Successfully stopped node {{.name}}", out.V{"name": machineName})
},
Expand Down
3 changes: 1 addition & 2 deletions cmd/minikube/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ var serviceCmd = &cobra.Command{
var services service.URLs
services, err := service.GetServiceURLs(co.API, co.Config.Name, namespace, serviceURLTemplate)
if err != nil {
out.FatalT("Failed to get service URL: {{.error}}", out.V{"error": err})
out.ErrT(style.Notice, "Check that minikube is running and that you have specified the correct namespace (-n flag) if required.")
out.ErrT(style.Fatal, "Failed to get service URL - check that minikube is running and that you have specified the correct namespace (-n flag) if required: {{.error}}", out.V{"error": err})
os.Exit(reason.ExSvcUnavailable)
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/minikube/cmd/service_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ var serviceListCmd = &cobra.Command{

serviceURLs, err := service.GetServiceURLs(co.API, co.Config.Name, serviceListNamespace, serviceURLTemplate)
if err != nil {
out.FatalT("Failed to get service URL: {{.error}}", out.V{"error": err})
out.ErrT(style.Notice, "Check that minikube is running and that you have specified the correct namespace (-n flag) if required.")
out.ErrT(style.Fatal, "Failed to get service URL - check that minikube is running and that you have specified the correct namespace (-n flag) if required: {{.error}}", out.V{"error": err})
os.Exit(reason.ExSvcUnavailable)
}
serviceURLs = updatePortsAndURLs(serviceURLs, co)
Expand Down
9 changes: 2 additions & 7 deletions pkg/minikube/out/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,6 @@ func SuccessT(format string, a ...V) {
Step(style.Success, format, a...)
}

// FatalT is a shortcut for writing a templated fatal message to stderr
func FatalT(format string, a ...V) {
ErrT(style.Fatal, format, a...)
}

// WarningT is a shortcut for writing a templated warning message to stderr
func WarningT(format string, a ...V) {
if JSON {
Expand Down Expand Up @@ -368,12 +363,12 @@ func LogEntries(msg string, err error, entries map[string][]string) {
func displayError(msg string, err error) {
klog.Warningf(fmt.Sprintf("%s: %v", msg, err))
if JSON {
FatalT("{{.msg}}: {{.err}}", V{"msg": translate.T(msg), "err": err})
ErrT(style.Fatal, "{{.msg}}: {{.err}}", V{"msg": translate.T(msg), "err": err})
return
}
// use Warning because Error will display a duplicate message to stderr
ErrT(style.Empty, "")
FatalT("{{.msg}}: {{.err}}", V{"msg": translate.T(msg), "err": err})
ErrT(style.Fatal, "{{.msg}}: {{.err}}", V{"msg": translate.T(msg), "err": err})
ErrT(style.Empty, "")
displayGitHubIssueMessage()
}
Expand Down