From 4ba2155996359eabd8800d1fbf3e3a9777c80490 Mon Sep 17 00:00:00 2001 From: Denis Isaev <denis@golangci.com> Date: Mon, 10 Jun 2019 10:45:36 +0300 Subject: [PATCH] fix #529: exit with code 7 when error was logged --- pkg/commands/run.go | 16 +++++++++++++--- pkg/exitcodes/exitcodes.go | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 521a1071..597d26d6 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -415,13 +415,23 @@ func (e *Executor) setupExitCode(ctx context.Context) { if ctx.Err() != nil { e.exitCode = exitcodes.Timeout e.log.Errorf("Deadline exceeded: try increase it by passing --deadline option") + return } - if e.exitCode == exitcodes.Success && - (os.Getenv("GL_TEST_RUN") == "1" || os.Getenv("FAIL_ON_WARNINGS") == "1") && - len(e.reportData.Warnings) != 0 { + if e.exitCode != exitcodes.Success { + return + } + needFailOnWarnings := (os.Getenv("GL_TEST_RUN") == "1" || os.Getenv("FAIL_ON_WARNINGS") == "1") + if needFailOnWarnings && len(e.reportData.Warnings) != 0 { e.exitCode = exitcodes.WarningInTest + return + } + + if e.reportData.Error != "" { + // it's a case e.g. when typecheck linter couldn't parse and error and just logged it + e.exitCode = exitcodes.ErrorWasLogged + return } } diff --git a/pkg/exitcodes/exitcodes.go b/pkg/exitcodes/exitcodes.go index 4a5f8d99..7c74a299 100644 --- a/pkg/exitcodes/exitcodes.go +++ b/pkg/exitcodes/exitcodes.go @@ -8,6 +8,7 @@ const ( Timeout = 4 NoGoFiles = 5 NoConfigFileDetected = 6 + ErrorWasLogged = 7 ) type ExitError struct {