Golangci-lint: failed to load package due to export data.

Created on 22 Jul 2020  路  4Comments  路  Source: golangci/golangci-lint

When running golangci-lint locally, everything passes with no errors. When I put up the Github Action it yields a new error;

  level=warning msg="[runner] Can't run linter unused: buildir: failed to load package tensorflow: could not load export data: no export data for \"github.com/tensorflow/tensorflow/tensorflow/go\""

Unfortunately, I can't solve this problem by skipping files that import tensorflow since they're still analyzed and will yield this error. I suspect the full-solution is to properly install tensorflow (which seems very unnecessary) and I'd rather be able to silence this error somehow?

  • [X] Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • [X] Yes, I've searched similar issues on GitHub and didn't find any.
  • [X] Yes, I've included all information below (version, config, etc).

Please include the following information:

1.26.x

$ golangci-lint --version
# golangci-lint has version 1.26.0 built from 6bd10d0 on 2020-05-01T15:26:22Z

Config file

$ cat .golangci.yml
linters-settings:
  depguard:
    list-type: blacklist
    packages:
      # logging is allowed only by logutils.Log, logrus
      # is allowed to use only in logutils package
      - github.com/sirupsen/logrus
    packages-with-error-message:
      - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
  dupl:
    threshold: 200
  goconst:
    min-len: 2
    min-occurrences: 2
  gocritic:
    settings:
      rangeValCopy:
        sizeThreshold: 512
      hugeParam:
        sizeThreshold: 512
    enabled-tags:
      - diagnostic
      - experimental
      - opinionated
      - performance
      - style
    disabled-checks:
      - dupImport # https://github.com/go-critic/go-critic/issues/845
      - ifElseChain
      - octalLiteral
      - whyNoLint
      - wrapperFunc
      - docStub
      - importShadow
      - unnamedResult
      - commentedOutCode
      - exitAfterDefer
      - emptyStringTest
      - paramTypeCombine
  gosimple:
    disabled-checks:
      - S1023
      - S1000
  gocyclo:
    min-complexity: 100
  goimports:
    local-prefixes: github.com/golangci/golangci-lint
  golint:
    min-confidence: 0.8
  govet:
    check-shadowing: false
    settings:
      printf:
        funcs:
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
          - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
  maligned:
    suggest-new: true
  nolintlint:
    allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
    allow-unused: false # report any unused nolint directives
    require-explanation: false # don't require an explanation for nolint directives
    require-specific: false # don't require nolint directives to be specific about which linter is being skipped

linters:
  # please, do not use `enable-all`: it's deprecated and will be removed soon.
  # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
  disable-all: true
  enable:
    - bodyclose
    - deadcode
    - depguard
    - dogsled
    - dupl
    - gocritic
    - gocyclo
    - gofmt
    - goimports
    - golint
    - goprintffuncname
    - gosimple
    - govet
    - interfacer
    - nakedret
    - nolintlint
    - rowserrcheck
    - scopelint
    - staticcheck
    - structcheck
    - stylecheck
    - typecheck
    - unparam
    - unused
    - varcheck
    - whitespace

  # don't enable:
  # - asciicheck
  # - gochecknoglobals
  # - gocognit
  # - godot
  # - godox
  # - goerr113
  # - maligned
  # - nestif
  # - prealloc
  # - testpackage
  # - wsl

issues:
  # Excluding configuration per-path, per-linter, per-text and per-source
  exclude-rules:
    - path: _test\.go
      linters:
        - gomnd

    # https://github.com/go-critic/go-critic/issues/926
    - linters:
        - gocritic
      text: "unnecessaryDefer:"

run:
  modules-download-mode: vendor

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
  golangci-lint-version: 1.29.x # use the fixed version to not introduce new linters unexpectedly
  prepare:
    - echo "here I can run custom commands, but no preparation needed for this repo"

Go environment

$ go version && go env
# failure only occurs in a github action

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
# failure only occurs in a github action

bug

Most helpful comment

This is unfortunately not possible in my case. I'm developing on a Mac for Linux systems, and we depend on github.com/coreos/go-systemd/v22/sdjournal, which wraps systemd's C API. Beacuse this is not available on non-Linux systems (AFAICT), we can no longer run the linter on our Macs.

Would it be possible to add some way to ignore these dependencies? It's unfortunate that adding a dependency prevents us from being able to run a static analysis tool like a linter.

All 4 comments

Hey, thank you for opening your first Issue ! 馃檪 If you would like to contribute we have a guide for contributors.

+1 on this. I'm hitting this with github.com/coreos/go-systemd/v22/sdjournal, which has CGo dependencies, just like tensorflow.

ERRO Running error: buildir: failed to load package sdjournal: could not load export data: no export data for "github.com/coreos/go-systemd/v22/sdjournal"

If I set CGO_ENABLED=0, I get

Running error: buildir: failed to load package dlopen: could not load export data: no export data for "github.com/coreos/go-systemd/v22/internal/dlopen" 

closing, just need to install cgo libraries properly so they can be compiled.

This is unfortunately not possible in my case. I'm developing on a Mac for Linux systems, and we depend on github.com/coreos/go-systemd/v22/sdjournal, which wraps systemd's C API. Beacuse this is not available on non-Linux systems (AFAICT), we can no longer run the linter on our Macs.

Would it be possible to add some way to ignore these dependencies? It's unfortunate that adding a dependency prevents us from being able to run a static analysis tool like a linter.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kpeu3i picture kpeu3i  路  3Comments

simonpasquier picture simonpasquier  路  4Comments

atc0005 picture atc0005  路  4Comments

jirfag picture jirfag  路  3Comments

nektro picture nektro  路  3Comments