Skip to content
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

failure is now an error rather than a warning since 1.44.0 #2577

Closed
4 tasks done
OscarVanL opened this issue Feb 16, 2022 · 3 comments
Closed
4 tasks done

failure is now an error rather than a warning since 1.44.0 #2577

OscarVanL opened this issue Feb 16, 2022 · 3 comments
Labels
question Further information is requested

Comments

@OscarVanL
Copy link

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

Our company uses a monorepo which we lint using golangci-lint. There are some imports of packages that use Cgo code which Mac developers cannot build.

In previous versions of golangci-lint, such as 1.43.0, this just presented a warning that the goanalysis_metalinter stage failed to run, but the linter would succeed.

This allowed our devs to run the linter locally on the stuff they were concerned with, then our CI would run the linter against our whole codebase (including the Cgo stuff).

oscar@oscar-mbp src % golangci-lint --version
golangci-lint has version v1.43.0 built from (unknown, mod sum: "h1:SLwZFEmDgopqZpfP495zCtV9REUf551JJlJ51Ql7NZA=") on (unknown)
oscar@oscar-mbp src % golangci-lint run --sort-results --config ../.golangci-enforced.yml  --fix
WARN [runner] Can't run linter goanalysis_metalinter: inspect: failed to load package ******: could not load export data: no export data for "gitlab.com/-----/*******-go"

Now since updating to 1.44.0, this now causes Mac developers to have the linter fail, and no exclusions or skip-dirs values avoid the failure.

oscar@oscar-mbp src % golangci-lint --version
golangci-lint has version v1.44.0 built from (unknown, mod sum: "h1:YJPouGNQEdK+x2KsCpWMIBy0q6MSuxHjkWMxJMNj/DU=") on (unknown)
oscar@oscar-mbp src % golangci-lint run --sort-results --config ../.golangci-enforced.yml  --fix
WARN [runner] Can't run linter goanalysis_metalinter: inspect: failed to load package ******: could not load export data: no export data for "gitlab.com/-----/*******-go"
ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: inspect: failed to load package *******: could not load export data: no export data for "gitlab.com/-----/*******-go"

It would be nice if this just caused a warning, not a failure. Alternatively it would be nice if there was something that could be changed in the linter .yml config to skip certain packages that use Cgo code. I don't believe there's anything I can add to our .yml files that would solve this.

Version of golangci-lint

before (warning only)

$ golangci-lint --version
golangci-lint has version v1.43.0 built from (unknown, mod sum: "h1:SLwZFEmDgopqZpfP495zCtV9REUf551JJlJ51Ql7NZA=") on (unknown)

now (failures)

$ golangci-lint --version
golangci-lint has version v1.44.0 built from (unknown, mod sum: "h1:YJPouGNQEdK+x2KsCpWMIBy0q6MSuxHjkWMxJMNj/DU=") on (unknown)

Configuration file

$ cat .golangci.yml
# paste output here

Go environment

$ go version && go env
go version go1.17.6 darwin/amd64
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/oscar/Library/Caches/go-build"
GOENV="/Users/oscar/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/oscar/go/pkg/mod"
GONOPROXY="gitlab.com/------/*,github.com/------/*"
GONOSUMDB="gitlab.com/------/*,github.com/------/*"
GOOS="darwin"
GOPATH="/Users/oscar/go"
GOPRIVATE="gitlab.com/------/*,github.com/------/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/oscar/sdk/go1.17.6"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/oscar/sdk/go1.17.6/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/oscar/go/src/gitlab.com/------/---/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z4/tjbsqpbj5pz3_mh9jzb4vhxw0000gn/T/go-build2130917196=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v --sort-results --config ../.golangci-enforced.yml  --fix
INFO [config_reader] Used config file ../.golangci-enforced.yml 
INFO [lintersdb] Active 27 linters: [asciicheck bidichk bodyclose deadcode durationcheck errcheck exhaustive exportloopref goimports gomoddirectives gosimple govet importas ineffassign makezero nilerr noctx nolintlint predeclared staticcheck thelper typecheck unconvert unparam unused varcheck wastedassign] 
INFO [loader] Go packages loading at mode 575 (imports|compiled_files|deps|exports_file|files|name|types_sizes) took 3.353112351s 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 63.960641ms 
INFO [linters context] importas settings found, but no aliases listed. List aliases under alias: key. 
INFO [linters context/goanalysis] analyzers took 8m45.758959855s with top 10 stages: bidichk: 4m21.520773337s, buildir: 1m18.284510654s, wastedassign: 21.543788956s, buildssa: 21.106679526s, nilness: 16.516473361s, goimports: 11.927896551s, exhaustive: 6.866076876s, unparam: 6.51882134s, printf: 5.955050487s, ctrlflow: 5.803888925s 
WARN [runner] Can't run linter goanalysis_metalinter: inspect: failed to load package pmx: could not load export data: no export data for "gitlab.com/pexip/pmx-go" 
INFO [runner] processing took 5.872µs with stages: max_same_issues: 2.024µs, nolint: 1.79µs, skip_dirs: 340ns, max_from_linter: 192ns, cgo: 149ns, autogenerated_exclude: 129ns, filename_unadjuster: 127ns, identifier_marker: 127ns, uniq_by_line: 122ns, path_prettifier: 120ns, skip_files: 118ns, source_code: 113ns, exclude: 111ns, max_per_file_from_linter: 65ns, sort_results: 62ns, exclude-rules: 61ns, diff: 57ns, path_shortener: 56ns, severity-rules: 55ns, path_prefixer: 54ns 
INFO [runner] linters took 25.212941809s with stages: goanalysis_metalinter: 25.212898392s 
ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: inspect: failed to load package ******: could not load export data: no export data for "gitlab.com/*****/******-go"
 
INFO Memory: 287 samples, avg is 1732.0MB, max is 2382.7MB 
INFO Execution took 28.642381s

Code example or link to a public repository

// add your code here
@OscarVanL OscarVanL added the bug Something isn't working label Feb 16, 2022
@bombsimon
Copy link
Member

This was reported in #2357 and addressed in #2471.

My reasoning for the implementation was that errors loading or running any of the configured linters should be treated as a non successful run and thus exit with a non-zero exit code. The way it's implemented is that every linter will still run, it's just the exit code that is changed. This is also why #2410 got rejected since that was of importance.

We actually had the opposite problem in CI where we did want to fail CI if any linter failed loading. Without this fix we had to pipe STDERR to STDOUT and grep for specific patterns which isn't very reliable or idiomatic.

I suggest you either ignore any errors if you don't care what linters were run with something like

golangci-lint run || true

Or actually ensure you run the proper configuration that is expected to work.

[ $(uname -s) = "Darwin" ] && cfg=".golangci.macos.yml" || cfg="golangci.yml"
golangci-lint run --config $cfg

@ldez
Copy link
Member

ldez commented Feb 16, 2022

It's a kind of duplicate of #2523

@ldez ldez changed the title goanalysis_metalinter failure is now an error rather than a warning since 1.44.0 failure is now an error rather than a warning since 1.44.0 Feb 16, 2022
@ldez ldez added question Further information is requested and removed bug Something isn't working labels Feb 16, 2022
@OscarVanL
Copy link
Author

Thanks for these suggestions, since this isn't a bug I'll close this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants