From 9a218235b9157c5f533c93f65a57e737c4298dcc Mon Sep 17 00:00:00 2001 From: Marlon Gamez Date: Thu, 22 Apr 2021 15:37:40 -0700 Subject: [PATCH 1/7] bring back error coloring --- cmd/skaffold/app/cmd/cmd.go | 10 ++++--- cmd/skaffold/skaffold.go | 3 +- pkg/skaffold/color/formatter.go | 13 ++++++--- pkg/skaffold/color/formatter_test.go | 14 +++++----- pkg/skaffold/util/term.go | 23 +++++++++++++++ pkg/skaffold/util/term_test.go | 42 ++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 16 deletions(-) diff --git a/cmd/skaffold/app/cmd/cmd.go b/cmd/skaffold/app/cmd/cmd.go index daf090148bc..f04b1c17f8f 100644 --- a/cmd/skaffold/app/cmd/cmd.go +++ b/cmd/skaffold/app/cmd/cmd.go @@ -56,7 +56,7 @@ const ( HouseKeepingMessagesAllowedAnnotation = "skaffold_annotation_housekeeping_allowed" ) -func NewSkaffoldCommand(out, err io.Writer) *cobra.Command { +func NewSkaffoldCommand(out, errOut io.Writer) *cobra.Command { updateMsg := make(chan string, 1) surveyPrompt := make(chan bool, 1) metricsPrompt := make(chan bool, 1) @@ -75,8 +75,10 @@ func NewSkaffoldCommand(out, err io.Writer) *cobra.Command { opts.Command = cmd.Use instrumentation.SetCommand(cmd.Use) - - out = color.SetupColors(out, defaultColor, forceColors) + out, err := color.SetupColors(out, defaultColor, forceColors) + if err != nil { + return err + } if timestamps { l := logrus.New() l.SetOutput(out) @@ -88,7 +90,7 @@ func NewSkaffoldCommand(out, err io.Writer) *cobra.Command { cmd.Root().SetOutput(out) // Setup logs - if err := setUpLogs(err, v, timestamps); err != nil { + if err := setUpLogs(errOut, v, timestamps); err != nil { return err } diff --git a/cmd/skaffold/skaffold.go b/cmd/skaffold/skaffold.go index db8c3425e3d..15b7b210f6c 100644 --- a/cmd/skaffold/skaffold.go +++ b/cmd/skaffold/skaffold.go @@ -38,7 +38,8 @@ func main() { if errors.Is(err, context.Canceled) { logrus.Debugln("ignore error since context is cancelled:", err) } else { - color.Red.Fprintln(os.Stderr, err) + errOut, _ := color.SetupColors(os.Stderr, color.DefaultColorCode, false) + color.Red.Fprintln(errOut, err) code = exitCode(err) } } diff --git a/pkg/skaffold/color/formatter.go b/pkg/skaffold/color/formatter.go index 078489c3344..8c4cac68502 100644 --- a/pkg/skaffold/color/formatter.go +++ b/pkg/skaffold/color/formatter.go @@ -37,9 +37,14 @@ func init() { } // SetupColors conditionally wraps the input `Writer` with a color enabled `Writer`. -func SetupColors(out io.Writer, defaultColor int, forceColors bool) io.Writer { +func SetupColors(out io.Writer, defaultColor int, forceColors bool) (io.Writer, error) { _, isTerm := util.IsTerminal(out) - useColors := isTerm || forceColors + supportsColor, err := util.SupportsColor() + if err != nil { + return out, err + } + + useColors := (isTerm && supportsColor) || forceColors if useColors { // Use EnableColorsStdout to enable use of color on Windows useColors = false // value is updated if color-enablement is successful @@ -65,9 +70,9 @@ func SetupColors(out io.Writer, defaultColor int, forceColors bool) io.Writer { }[defaultColor] if useColors { - return NewWriter(out) + return NewWriter(out), nil } - return out + return out, nil } // Color can be used to format text so it can be printed to the terminal in color. diff --git a/pkg/skaffold/color/formatter_test.go b/pkg/skaffold/color/formatter_test.go index 17eb6b71c12..b57ae8a05e5 100644 --- a/pkg/skaffold/color/formatter_test.go +++ b/pkg/skaffold/color/formatter_test.go @@ -36,7 +36,7 @@ func TestFprintln(t *testing.T) { defer func() { SetupColors(nil, DefaultColorCode, false) }() var b bytes.Buffer - cw := SetupColors(&b, 0, true) + cw, _ := SetupColors(&b, 0, true) Green.Fprintln(cw, "2", "less", "chars!") compareText(t, "\033[32m2 less chars!\033[0m\n", b.String()) @@ -46,7 +46,7 @@ func TestFprintf(t *testing.T) { defer func() { SetupColors(nil, DefaultColorCode, false) }() var b bytes.Buffer - cw := SetupColors(&b, 0, true) + cw, _ := SetupColors(&b, 0, true) Green.Fprintf(cw, "It's been %d %s", 1, "week") compareText(t, "\033[32mIt's been 1 week\033[0m", b.String()) @@ -55,7 +55,7 @@ func TestFprintf(t *testing.T) { func TestFprintlnNoTTY(t *testing.T) { var b bytes.Buffer - cw := SetupColors(&b, 0, false) + cw, _ := SetupColors(&b, 0, false) Green.Fprintln(cw, "2", "less", "chars!") compareText(t, "2 less chars!\n", b.String()) @@ -64,7 +64,7 @@ func TestFprintlnNoTTY(t *testing.T) { func TestFprintfNoTTY(t *testing.T) { var b bytes.Buffer - cw := SetupColors(&b, 0, false) + cw, _ := SetupColors(&b, 0, false) Green.Fprintf(cw, "It's been %d %s", 1, "week") compareText(t, "It's been 1 week", b.String()) @@ -73,7 +73,7 @@ func TestFprintfNoTTY(t *testing.T) { func TestFprintlnDefaultColor(t *testing.T) { var b bytes.Buffer - cw := SetupColors(&b, 34, true) + cw, _ := SetupColors(&b, 34, true) Default.Fprintln(cw, "2", "less", "chars!") compareText(t, "\033[34m2 less chars!\033[0m\n", b.String()) } @@ -81,7 +81,7 @@ func TestFprintlnDefaultColor(t *testing.T) { func TestFprintlnChangeDefaultToNone(t *testing.T) { var b bytes.Buffer - cw := SetupColors(&b, 0, true) + cw, _ := SetupColors(&b, 0, true) Default.Fprintln(cw, "2", "less", "chars!") compareText(t, "2 less chars!\n", b.String()) } @@ -89,7 +89,7 @@ func TestFprintlnChangeDefaultToNone(t *testing.T) { func TestFprintlnChangeDefaultToUnknown(t *testing.T) { var b bytes.Buffer - cw := SetupColors(&b, -1, true) + cw, _ := SetupColors(&b, -1, true) Default.Fprintln(cw, "2", "less", "chars!") compareText(t, "2 less chars!\n", b.String()) } diff --git a/pkg/skaffold/util/term.go b/pkg/skaffold/util/term.go index abf0d6233ab..b78d809900f 100644 --- a/pkg/skaffold/util/term.go +++ b/pkg/skaffold/util/term.go @@ -18,10 +18,15 @@ package util import ( "io" + "os/exec" + "strconv" + "strings" "golang.org/x/term" ) +var colors = tputColors + func IsTerminal(w io.Writer) (uintptr, bool) { type descriptor interface { Fd() uintptr @@ -35,3 +40,21 @@ func IsTerminal(w io.Writer) (uintptr, bool) { return 0, false } + +func SupportsColor() (bool, error) { + res, err := colors() + if err != nil { + return false, err + } + + numColors, err := strconv.Atoi(strings.TrimSpace(string(res))) + if err != nil { + return false, err + } + + return numColors != 0, nil +} + +func tputColors() ([]byte, error) { + return exec.Command("tput", "colors").Output() +} diff --git a/pkg/skaffold/util/term_test.go b/pkg/skaffold/util/term_test.go index cb477a0ab6e..cad3256acb5 100644 --- a/pkg/skaffold/util/term_test.go +++ b/pkg/skaffold/util/term_test.go @@ -18,6 +18,7 @@ package util import ( "bytes" + "errors" "testing" "github.com/GoogleContainerTools/skaffold/testutil" @@ -31,3 +32,44 @@ func TestIsNotTerminal(t *testing.T) { testutil.CheckDeepEqual(t, uintptr(0x00), termFd) testutil.CheckDeepEqual(t, false, isTerm) } + +func TestSupportsColor(t *testing.T) { + tests := []struct { + description string + colorsOutput []byte + shouldErr bool + expected bool + }{ + { + description: "Supports 256 colors", + colorsOutput: []byte("256"), + expected: true, + }, + { + description: "Supports 0 colors", + colorsOutput: []byte("0"), + expected: false, + }, + { + description: "Errors", + colorsOutput: []byte("-1"), + shouldErr: true, + expected: false, + }, + } + + for _, test := range tests { + testutil.Run(t, test.description, func(t *testutil.T) { + t.Override(&colors, func() ([]byte, error) { + if test.shouldErr { + return nil, errors.New("error") + } + + return test.colorsOutput, nil + }) + + supportsColors, err := SupportsColor() + t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expected, supportsColors) + }) + } +} From c7911daef4aae3d48f8c2d37a82eaecf5abd8083 Mon Sep 17 00:00:00 2001 From: Marlon Gamez Date: Fri, 23 Apr 2021 11:35:31 -0700 Subject: [PATCH 2/7] more descriptive error --- pkg/skaffold/util/term.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/skaffold/util/term.go b/pkg/skaffold/util/term.go index b78d809900f..3a050c396d1 100644 --- a/pkg/skaffold/util/term.go +++ b/pkg/skaffold/util/term.go @@ -17,6 +17,7 @@ limitations under the License. package util import ( + "fmt" "io" "os/exec" "strconv" @@ -44,7 +45,7 @@ func IsTerminal(w io.Writer) (uintptr, bool) { func SupportsColor() (bool, error) { res, err := colors() if err != nil { - return false, err + return false, fmt.Errorf("checking terminal colors: %w", err) } numColors, err := strconv.Atoi(strings.TrimSpace(string(res))) From 65202eea472cc4c713b9c11691ef8de5457973b7 Mon Sep 17 00:00:00 2001 From: Marlon Gamez Date: Fri, 23 Apr 2021 13:06:51 -0700 Subject: [PATCH 3/7] treat tput error as not supporting colors --- cmd/skaffold/app/cmd/cmd.go | 5 +---- cmd/skaffold/skaffold.go | 2 +- pkg/skaffold/color/formatter.go | 11 ++++------- pkg/skaffold/color/formatter_test.go | 14 +++++++------- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/cmd/skaffold/app/cmd/cmd.go b/cmd/skaffold/app/cmd/cmd.go index f04b1c17f8f..a948514fb7b 100644 --- a/cmd/skaffold/app/cmd/cmd.go +++ b/cmd/skaffold/app/cmd/cmd.go @@ -75,10 +75,7 @@ func NewSkaffoldCommand(out, errOut io.Writer) *cobra.Command { opts.Command = cmd.Use instrumentation.SetCommand(cmd.Use) - out, err := color.SetupColors(out, defaultColor, forceColors) - if err != nil { - return err - } + out := color.SetupColors(out, defaultColor, forceColors) if timestamps { l := logrus.New() l.SetOutput(out) diff --git a/cmd/skaffold/skaffold.go b/cmd/skaffold/skaffold.go index 15b7b210f6c..810bb3e84fe 100644 --- a/cmd/skaffold/skaffold.go +++ b/cmd/skaffold/skaffold.go @@ -38,7 +38,7 @@ func main() { if errors.Is(err, context.Canceled) { logrus.Debugln("ignore error since context is cancelled:", err) } else { - errOut, _ := color.SetupColors(os.Stderr, color.DefaultColorCode, false) + errOut := color.SetupColors(os.Stderr, color.DefaultColorCode, false) color.Red.Fprintln(errOut, err) code = exitCode(err) } diff --git a/pkg/skaffold/color/formatter.go b/pkg/skaffold/color/formatter.go index 8c4cac68502..5d9aa6fb1dd 100644 --- a/pkg/skaffold/color/formatter.go +++ b/pkg/skaffold/color/formatter.go @@ -37,12 +37,9 @@ func init() { } // SetupColors conditionally wraps the input `Writer` with a color enabled `Writer`. -func SetupColors(out io.Writer, defaultColor int, forceColors bool) (io.Writer, error) { +func SetupColors(out io.Writer, defaultColor int, forceColors bool) io.Writer { _, isTerm := util.IsTerminal(out) - supportsColor, err := util.SupportsColor() - if err != nil { - return out, err - } + supportsColor, _ := util.SupportsColor() useColors := (isTerm && supportsColor) || forceColors if useColors { @@ -70,9 +67,9 @@ func SetupColors(out io.Writer, defaultColor int, forceColors bool) (io.Writer, }[defaultColor] if useColors { - return NewWriter(out), nil + return NewWriter(out) } - return out, nil + return out } // Color can be used to format text so it can be printed to the terminal in color. diff --git a/pkg/skaffold/color/formatter_test.go b/pkg/skaffold/color/formatter_test.go index b57ae8a05e5..17eb6b71c12 100644 --- a/pkg/skaffold/color/formatter_test.go +++ b/pkg/skaffold/color/formatter_test.go @@ -36,7 +36,7 @@ func TestFprintln(t *testing.T) { defer func() { SetupColors(nil, DefaultColorCode, false) }() var b bytes.Buffer - cw, _ := SetupColors(&b, 0, true) + cw := SetupColors(&b, 0, true) Green.Fprintln(cw, "2", "less", "chars!") compareText(t, "\033[32m2 less chars!\033[0m\n", b.String()) @@ -46,7 +46,7 @@ func TestFprintf(t *testing.T) { defer func() { SetupColors(nil, DefaultColorCode, false) }() var b bytes.Buffer - cw, _ := SetupColors(&b, 0, true) + cw := SetupColors(&b, 0, true) Green.Fprintf(cw, "It's been %d %s", 1, "week") compareText(t, "\033[32mIt's been 1 week\033[0m", b.String()) @@ -55,7 +55,7 @@ func TestFprintf(t *testing.T) { func TestFprintlnNoTTY(t *testing.T) { var b bytes.Buffer - cw, _ := SetupColors(&b, 0, false) + cw := SetupColors(&b, 0, false) Green.Fprintln(cw, "2", "less", "chars!") compareText(t, "2 less chars!\n", b.String()) @@ -64,7 +64,7 @@ func TestFprintlnNoTTY(t *testing.T) { func TestFprintfNoTTY(t *testing.T) { var b bytes.Buffer - cw, _ := SetupColors(&b, 0, false) + cw := SetupColors(&b, 0, false) Green.Fprintf(cw, "It's been %d %s", 1, "week") compareText(t, "It's been 1 week", b.String()) @@ -73,7 +73,7 @@ func TestFprintfNoTTY(t *testing.T) { func TestFprintlnDefaultColor(t *testing.T) { var b bytes.Buffer - cw, _ := SetupColors(&b, 34, true) + cw := SetupColors(&b, 34, true) Default.Fprintln(cw, "2", "less", "chars!") compareText(t, "\033[34m2 less chars!\033[0m\n", b.String()) } @@ -81,7 +81,7 @@ func TestFprintlnDefaultColor(t *testing.T) { func TestFprintlnChangeDefaultToNone(t *testing.T) { var b bytes.Buffer - cw, _ := SetupColors(&b, 0, true) + cw := SetupColors(&b, 0, true) Default.Fprintln(cw, "2", "less", "chars!") compareText(t, "2 less chars!\n", b.String()) } @@ -89,7 +89,7 @@ func TestFprintlnChangeDefaultToNone(t *testing.T) { func TestFprintlnChangeDefaultToUnknown(t *testing.T) { var b bytes.Buffer - cw, _ := SetupColors(&b, -1, true) + cw := SetupColors(&b, -1, true) Default.Fprintln(cw, "2", "less", "chars!") compareText(t, "2 less chars!\n", b.String()) } From ac9ea5d9135cb4ce216eafd29cab34736e97c424 Mon Sep 17 00:00:00 2001 From: Marlon Gamez Date: Mon, 26 Apr 2021 15:42:07 -0700 Subject: [PATCH 4/7] move string into constants --- pkg/skaffold/constants/constants.go | 2 ++ pkg/skaffold/util/tar.go | 4 +++- pkg/skaffold/util/tar_test.go | 3 ++- pkg/skaffold/util/term.go | 7 +++++++ pkg/skaffold/util/term_test.go | 6 ++++++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/skaffold/constants/constants.go b/pkg/skaffold/constants/constants.go index c2fe7ebbb68..44df4093e52 100644 --- a/pkg/skaffold/constants/constants.go +++ b/pkg/skaffold/constants/constants.go @@ -69,6 +69,8 @@ const ( LeeroyAppResponse = "leeroooooy app!!\n" GithubIssueLink = "https://github.com/GoogleContainerTools/skaffold/issues/new" + + Windows = "windows" ) type Phase string diff --git a/pkg/skaffold/util/tar.go b/pkg/skaffold/util/tar.go index 0f9c0ec7ef7..0fb8361fd7b 100644 --- a/pkg/skaffold/util/tar.go +++ b/pkg/skaffold/util/tar.go @@ -27,6 +27,8 @@ import ( "time" "github.com/sirupsen/logrus" + + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" ) type headerModifier func(*tar.Header) @@ -145,7 +147,7 @@ func addFileToTar(root string, src string, dst string, tw *tar.Writer, hm header } // Code copied from https://github.com/moby/moby/blob/master/pkg/archive/archive_windows.go - if runtime.GOOS == "windows" { + if runtime.GOOS == constants.Windows { header.Mode = int64(chmodTarEntry(os.FileMode(header.Mode))) } if hm != nil { diff --git a/pkg/skaffold/util/tar_test.go b/pkg/skaffold/util/tar_test.go index 668f53e2317..a7ba384baea 100644 --- a/pkg/skaffold/util/tar_test.go +++ b/pkg/skaffold/util/tar_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -234,7 +235,7 @@ func TestCreateTarWithAbsolutePaths(t *testing.T) { } func TestAddFileToTarSymlinks(t *testing.T) { - if runtime.GOOS == "windows" { + if runtime.GOOS == constants.Windows { t.Skip("creating symlinks requires extra privileges on Windows") } diff --git a/pkg/skaffold/util/term.go b/pkg/skaffold/util/term.go index 3a050c396d1..a277ddc2bc8 100644 --- a/pkg/skaffold/util/term.go +++ b/pkg/skaffold/util/term.go @@ -20,10 +20,13 @@ import ( "fmt" "io" "os/exec" + "runtime" "strconv" "strings" "golang.org/x/term" + + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" ) var colors = tputColors @@ -43,6 +46,10 @@ func IsTerminal(w io.Writer) (uintptr, bool) { } func SupportsColor() (bool, error) { + if runtime.GOOS == constants.Windows { + return true, nil + } + res, err := colors() if err != nil { return false, fmt.Errorf("checking terminal colors: %w", err) diff --git a/pkg/skaffold/util/term_test.go b/pkg/skaffold/util/term_test.go index cad3256acb5..ebe6407ee9b 100644 --- a/pkg/skaffold/util/term_test.go +++ b/pkg/skaffold/util/term_test.go @@ -19,8 +19,10 @@ package util import ( "bytes" "errors" + "runtime" "testing" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" "github.com/GoogleContainerTools/skaffold/testutil" ) @@ -67,6 +69,10 @@ func TestSupportsColor(t *testing.T) { return test.colorsOutput, nil }) + if runtime.GOOS == constants.Windows { + test.expected = true + test.shouldErr = false + } supportsColors, err := SupportsColor() t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expected, supportsColors) From 83ee750f7b2420304a0b85dcbaa550e39bec48b9 Mon Sep 17 00:00:00 2001 From: Marlon Gamez Date: Wed, 28 Apr 2021 12:07:10 -0700 Subject: [PATCH 5/7] address readability feedback --- cmd/skaffold/skaffold.go | 2 ++ pkg/skaffold/util/term.go | 11 +++-------- pkg/skaffold/util/term_test.go | 29 ++++++++++++++++------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cmd/skaffold/skaffold.go b/cmd/skaffold/skaffold.go index 810bb3e84fe..7e4ea2e4dca 100644 --- a/cmd/skaffold/skaffold.go +++ b/cmd/skaffold/skaffold.go @@ -38,6 +38,8 @@ func main() { if errors.Is(err, context.Canceled) { logrus.Debugln("ignore error since context is cancelled:", err) } else { + // Because we use cobra flags to setup colors for the main run, we can't run SetupColors() + // for the entire skaffold run here, and have to call it again before we print an error errOut := color.SetupColors(os.Stderr, color.DefaultColorCode, false) color.Red.Fprintln(errOut, err) code = exitCode(err) diff --git a/pkg/skaffold/util/term.go b/pkg/skaffold/util/term.go index a277ddc2bc8..724ff2c7234 100644 --- a/pkg/skaffold/util/term.go +++ b/pkg/skaffold/util/term.go @@ -29,8 +29,6 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" ) -var colors = tputColors - func IsTerminal(w io.Writer) (uintptr, bool) { type descriptor interface { Fd() uintptr @@ -50,7 +48,8 @@ func SupportsColor() (bool, error) { return true, nil } - res, err := colors() + cmd := exec.Command("tput", "colors") + res, err := RunCmdOut(cmd) if err != nil { return false, fmt.Errorf("checking terminal colors: %w", err) } @@ -60,9 +59,5 @@ func SupportsColor() (bool, error) { return false, err } - return numColors != 0, nil -} - -func tputColors() ([]byte, error) { - return exec.Command("tput", "colors").Output() + return numColors > 0, nil } diff --git a/pkg/skaffold/util/term_test.go b/pkg/skaffold/util/term_test.go index ebe6407ee9b..50392dfbec5 100644 --- a/pkg/skaffold/util/term_test.go +++ b/pkg/skaffold/util/term_test.go @@ -38,37 +38,40 @@ func TestIsNotTerminal(t *testing.T) { func TestSupportsColor(t *testing.T) { tests := []struct { description string - colorsOutput []byte + colorsOutput string shouldErr bool expected bool }{ { description: "Supports 256 colors", - colorsOutput: []byte("256"), + colorsOutput: "256", expected: true, }, { description: "Supports 0 colors", - colorsOutput: []byte("0"), + colorsOutput: "0", expected: false, }, { - description: "Errors", - colorsOutput: []byte("-1"), - shouldErr: true, + description: "tput returns -1", + colorsOutput: "-1", expected: false, }, + { + description: "cmd run errors", + colorsOutput: "-1", + expected: false, + shouldErr: true, + }, } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { - t.Override(&colors, func() ([]byte, error) { - if test.shouldErr { - return nil, errors.New("error") - } - - return test.colorsOutput, nil - }) + if test.shouldErr { + t.Override(&DefaultExecCommand, testutil.CmdRunOutErr("tput colors", test.colorsOutput, errors.New("error"))) + } else { + t.Override(&DefaultExecCommand, testutil.CmdRunOut("tput colors", test.colorsOutput)) + } if runtime.GOOS == constants.Windows { test.expected = true test.shouldErr = false From 32f02099dc7bef3c4a3962e9ae32d8572afceeee Mon Sep 17 00:00:00 2001 From: Marlon Gamez Date: Tue, 4 May 2021 09:55:56 -0700 Subject: [PATCH 6/7] Update cmd/skaffold/skaffold.go Co-authored-by: Brian de Alwis --- cmd/skaffold/skaffold.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/skaffold/skaffold.go b/cmd/skaffold/skaffold.go index 7e4ea2e4dca..d0659d3eedf 100644 --- a/cmd/skaffold/skaffold.go +++ b/cmd/skaffold/skaffold.go @@ -38,8 +38,9 @@ func main() { if errors.Is(err, context.Canceled) { logrus.Debugln("ignore error since context is cancelled:", err) } else { - // Because we use cobra flags to setup colors for the main run, we can't run SetupColors() - // for the entire skaffold run here, and have to call it again before we print an error + // As we allow some color setup using CLI flags for the main run, we can't run SetupColors() + // for the entire skaffold run here. It's possible SetupColors() was never called, so call it again + // before we print an error to get the right coloring. errOut := color.SetupColors(os.Stderr, color.DefaultColorCode, false) color.Red.Fprintln(errOut, err) code = exitCode(err) From a5bfc843ab3330b3cf9a5599b853bc8a147204f0 Mon Sep 17 00:00:00 2001 From: Marlon Gamez Date: Tue, 4 May 2021 09:58:02 -0700 Subject: [PATCH 7/7] log error at debug level --- pkg/skaffold/color/formatter.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/skaffold/color/formatter.go b/pkg/skaffold/color/formatter.go index 5d9aa6fb1dd..414253321dd 100644 --- a/pkg/skaffold/color/formatter.go +++ b/pkg/skaffold/color/formatter.go @@ -24,6 +24,7 @@ import ( colors "github.com/heroku/color" "github.com/mattn/go-colorable" + "github.com/sirupsen/logrus" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) @@ -39,7 +40,10 @@ func init() { // SetupColors conditionally wraps the input `Writer` with a color enabled `Writer`. func SetupColors(out io.Writer, defaultColor int, forceColors bool) io.Writer { _, isTerm := util.IsTerminal(out) - supportsColor, _ := util.SupportsColor() + supportsColor, err := util.SupportsColor() + if err != nil { + logrus.Debugf("error checking for color support: %v", err) + } useColors := (isTerm && supportsColor) || forceColors if useColors {