golangci-lint icon indicating copy to clipboard operation
golangci-lint copied to clipboard

Can't parse date when running

Open J4cku opened this issue 2 years ago • 11 comments

Welcome

  • [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).
  • [X] Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

When running golangci-lint run -E gofmt I am shown an error:

WARN [linters context] structcheck is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: goimports: can't extract issues from gofmt diff output "--- /Users/jacek.leszczynski/RiderProjects/reporting-tools/go/rot/client/reporting.go.orig\t2022-08-10 12:30:31\n+++ /Users/jacek.leszczynski/RiderProjects/reporting-tools/go/rot/client/reporting.go\t2022-08-10 12:30:31\n@@ -4,8 +4,9 @@\n \t\"context\"\n \t\"encoding/json\"\n \t\"fmt\"\n-\t\"github.com/Fonoa-Tech/reporting-api/generated/contracts\"\n \t\"net/url\"\n+\n+\t\"github.com/Fonoa-Tech/reporting-api/generated/contracts\"\n )\n \n type ReportingClient struct {\n": can't parse patch: parsing time "2022-08-10 12:30:31" as "2006-01-02 15:04:05 -0700": cannot parse "" as "-0700"

Version of golangci-lint

golangci-lint has version 1.46.2 built from a333689 on 2022-05-17T06:05:08Z

Configuration file

---
run:
  timeout: 3m
  build-tags:
    - integration

linters:
  enable:
    - misspell
    - goimports
    - revive
    - gofmt
    - depguard
    - godot

Go environment

go version go1.18.2 darwin/arm64
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/jacek.leszczynski/Library/Caches/go-build"
GOENV="/Users/jacek.leszczynski/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/jacek.leszczynski/gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jacek.leszczynski/gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.18.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.18.2/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jacek.leszczynski/RiderProjects/reporting-tools/go/rot/go.mod"
GOWORK=""
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 arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jc/2hzf075172155k8m2zswff540000gq/T/go-build2249922677=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

INFO [config_reader] Config search paths: [./ /Users/jacek.leszczynski/RiderProjects/reporting-tools/go/rot /Users/jacek.leszczynski/RiderProjects/reporting-tools/go /Users/jacek.leszczynski/RiderProjects/reporting-tools /Users/jacek.leszczynski/RiderProjects /Users/jacek.leszczynski /Users /] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 16 linters: [deadcode depguard errcheck godot gofmt goimports gosimple govet ineffassign misspell revive staticcheck structcheck typecheck unused varcheck] 
INFO [loader] Using build tags: [integration]     
INFO [loader] Go packages loading at mode 575 (imports|deps|exports_file|files|name|types_sizes|compiled_files) took 379.585375ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 3.7755ms 
INFO [linters context/goanalysis] analyzers took 14.276696194s with top 10 stages: buildir: 9.462551828s, inspect: 803.317455ms, fact_deprecated: 507.355007ms, ctrlflow: 430.351534ms, nilness: 429.363872ms, printf: 362.387388ms, fact_purity: 344.798673ms, SA5012: 280.363134ms, the_only_name: 212.144167ms, typedness: 206.551703ms 
WARN [runner] Can't run linter goanalysis_metalinter: goimports: can't extract issues from gofmt diff output "--- /Users/jacek.leszczynski/RiderProjects/reporting-tools/go/rot/client/reporting.go.orig\t2022-08-10 12:33:15\n+++ /Users/jacek.leszczynski/RiderProjects/reporting-tools/go/rot/client/reporting.go\t2022-08-10 12:33:15\n@@ -4,8 +4,9 @@\n \t\"context\"\n \t\"encoding/json\"\n \t\"fmt\"\n-\t\"github.com/Fonoa-Tech/reporting-api/generated/contracts\"\n \t\"net/url\"\n+\n+\t\"github.com/Fonoa-Tech/reporting-api/generated/contracts\"\n )\n \n type ReportingClient struct {\n": can't parse patch: parsing time "2022-08-10 12:33:15" as "2006-01-02 15:04:05 -0700": cannot parse "" as "-0700" 
WARN [linters context] structcheck is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649. 
INFO [runner] processing took 2.708µs with stages: max_same_issues: 958ns, nolint: 334ns, max_from_linter: 333ns, skip_dirs: 208ns, severity-rules: 84ns, max_per_file_from_linter: 84ns, filename_unadjuster: 84ns, cgo: 83ns, autogenerated_exclude: 83ns, skip_files: 42ns, path_prefixer: 42ns, path_prettifier: 42ns, path_shortener: 42ns, sort_results: 42ns, diff: 42ns, exclude: 41ns, exclude-rules: 41ns, identifier_marker: 41ns, source_code: 41ns, uniq_by_line: 41ns 
INFO [runner] linters took 4.578902583s with stages: goanalysis_metalinter: 4.57884975s, structcheck: 10.291µs 
ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: goimports: can't extract issues from gofmt diff output "--- /Users/jacek.leszczynski/RiderProjects/reporting-tools/go/rot/client/reporting.go.orig\t2022-08-10 12:33:15\n+++ /Users/jacek.leszczynski/RiderProjects/reporting-tools/go/rot/client/reporting.go\t2022-08-10 12:33:15\n@@ -4,8 +4,9 @@\n \t\"context\"\n \t\"encoding/json\"\n \t\"fmt\"\n-\t\"github.com/Fonoa-Tech/reporting-api/generated/contracts\"\n \t\"net/url\"\n+\n+\t\"github.com/Fonoa-Tech/reporting-api/generated/contracts\"\n )\n \n type ReportingClient struct {\n": can't parse patch: parsing time "2022-08-10 12:33:15" as "2006-01-02 15:04:05 -0700": cannot parse "" as "-0700"
 
INFO Memory: 51 samples, avg is 823.6MB, max is 1302.8MB 
INFO Execution took 4.980535375s 

Code example or link to a public repository

Can't share code

J4cku avatar Aug 10 '22 10:08 J4cku

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

boring-cyborg[bot] avatar Aug 10 '22 10:08 boring-cyborg[bot]

Hello,

can you provide your git configuration? and the information of the diff installed on your system?

ldez avatar Aug 10 '22 12:08 ldez

diff --version                                                                                                                                       
Apple diff (based on FreeBSD diff)
git config --list-all

credential.helper=osxkeychain
user.name=Jacek Leszczyński
user.email=<my mail here>
http.sslverify=false
core.autocrlf=input
core.editor=atom --wait~
pull.ff=only
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
submodule.active=.

J4cku avatar Aug 10 '22 21:08 J4cku

It feels like your diff doesn't follow the specification for the timestamp format https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html

ldez avatar Aug 10 '22 22:08 ldez

@ldez But the date can be shown without a timezone.

I have a similar error: can't parse patch: parsing time \"2022-08-24 14:35:19\" as \"2006-01-02 15:04:05 -0700\": cannot parse \"\" as \"-0700\""

BorzdeG avatar Aug 24 '22 11:08 BorzdeG

The specification seems clear: the timezone is not optional.

The timestamp looks like ‘2002-02-21 23:30:39.942229878 -0800’ to indicate the date, time with fractional seconds, and time zone. The fractional seconds are omitted on hosts that do not support fractional timestamps.

I will try to find how to handle diff command that doesn't follow this spec.

ldez avatar Aug 24 '22 11:08 ldez

Created an issue in the library where the error occurs: https://github.com/sourcegraph/go-diff/issues/64

BorzdeG avatar Aug 24 '22 13:08 BorzdeG

Running tests on macOS gives the same error:

ERRO Running error: 1 error occurred:
	* can't run linter goanalysis_metalinter: goimports: can't extract issues from gofmt diff output "--- /Users/borz/Development/com.github/golangci/golangci-lint/internal/robustio/robustio.go.orig\t2022-08-24 17:18:51\n+++ /Users/borz/Development/com.github/golangci/golangci-lint/internal/robustio/robustio.go\t2022-08-24 17:18:51\n@@ -42,9 +42,9 @@\n // in this package attempt to mitigate.\n //\n // Errors considered ephemeral include:\n-// \t- syscall.ERROR_ACCESS_DENIED\n-// \t- syscall.ERROR_FILE_NOT_FOUND\n-// \t- internal/syscall/windows.ERROR_SHARING_VIOLATION\n+//   - syscall.ERROR_ACCESS_DENIED\n+//   - syscall.ERROR_FILE_NOT_FOUND\n+//   - internal/syscall/windows.ERROR_SHARING_VIOLATION\n //\n // This set may be expanded in the future; programs must not rely on the\n // non-ephemerality of any given error.\n": can't parse patch: parsing time "2022-08-24 17:18:51" as "2006-01-02 15:04:05 -0700": cannot parse "" as "-0700"
With your permission, I'll dig further with this issue

BorzdeG avatar Aug 24 '22 15:08 BorzdeG

The problem comes from the diff output.

Our CI runs a job on macOS/darwin.

go-diff has a pattern that follows GNU diff.

For me it's a problem with Apple diff.

ldez avatar Aug 24 '22 16:08 ldez

Any idea how to install different diff?

J4cku avatar Aug 24 '22 20:08 J4cku

brew install diffutils worked for me.

shepherdjerred avatar Aug 24 '22 22:08 shepherdjerred

Support for Apple's diff output was added in https://github.com/sourcegraph/go-diff/commit/7ef5f68ebea1885cdfa8bc710e3d666f95bec1cb, so upgrading the go-diff dependency will fix this issue.

fjl avatar Nov 07 '22 17:11 fjl

I will take a look

ldez avatar Nov 07 '22 18:11 ldez

brew install diffutils fixes the issue for me

Issue can't run linter goanalysis_metalinter: goimports: can't extract issues from gofmt diff output "--- ........ ..... ..... {\n": can't parse patch: parsing time "2022-11-08 16:49:57" as "2006-01-02 15:04:05 -0700": cannot parse "" as "-0700"

Environment Apple macOs ventura

Thanks @shepherdjerred

asalan316 avatar Nov 08 '22 15:11 asalan316

The problem with apple diff is now fixed upstream: https://github.com/sourcegraph/go-diff/pull/65

freeformz avatar Nov 08 '22 17:11 freeformz

And it looks like it was also updated, so next release should work with apple diff: https://github.com/golangci/golangci-lint/commit/58ebedda6341e2f67d4338eb1d8f75b4a54590d1

freeformz avatar Nov 08 '22 18:11 freeformz

brew install diffutils为我工作。

Thanks

itgcl avatar Nov 16 '22 04:11 itgcl

brew install diffutils is working for me.

thanks

priyankshah217 avatar Nov 24 '22 04:11 priyankshah217

brew install diffutils worked for me.

thanks

thomasshen-crypto avatar Dec 14 '22 03:12 thomasshen-crypto

brew install diffutils worked for me.

Thanks

rahulanand90 avatar Jan 03 '23 10:01 rahulanand90