Skip to content

"Gofmt: can't extract issues from gofmt diff output" error on Windows #1169

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

Closed
johny7 opened this issue May 29, 2020 · 3 comments
Closed

"Gofmt: can't extract issues from gofmt diff output" error on Windows #1169

johny7 opened this issue May 29, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@johny7
Copy link

johny7 commented May 29, 2020

Thank you for creating the issue!

  • 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).

Please include the following information:

Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.27.0 built from fb74c2e on 2020-05-13T18:45:55Z
Config file
$ cat .golangci.yml
cat: .golangci.yml: No such file or directory
Go environment
$ go version && go env
go version go1.14.1 windows/amd64
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\JOHNY5\AppData\Local\go-build
set GOENV=C:\Users\JOHNY5\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\JOHNY5\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\JOHNY5\AppData\Local\Temp\go-build157349350=/tmp/go-build -gno-record-gcc-switches
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -v
golangci-lint run -v --enable gofmt
level=info msg="[config_reader] Config search paths: [./ C:\\Work\\TTSProxy\\eeva\\tts-proxy C:\\Work\\TTSProxy\\eeva C:\\Work\\TTSProxy C:\\Work C:\\]"
level=info msg="[lintersdb] Active 11 linters: [deadcode errcheck gofmt gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"
level=info msg="[loader] Go packages loading at mode 575 (deps|exports_file|files|name|compiled_files|imports|types_sizes) took 686.4058ms"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 3.0023ms"
level=info msg="[linters context/goanalysis] analyzers took 36.1558208s with top 10 stages: buildir: 15.4160127s, printf: 5.048845s, ctrlflow: 5.0310511s, fact_deprecated: 5.0145283s, fact_purity: 4.945831s, inspect: 598.8551ms, gofmt: 56.0001ms, ineffassign: 5.9785ms, S1038: 2.9992ms, isgenerated: 1.9695ms"
level=warning msg="[runner] Can't run linter goanalysis_metalinter: gofmt: can't extract issues from gofmt diff output \"\": got no diffs from patch parser: []"
level=info msg="[linters context/goanalysis] analyzers took 103.9965ms with top 10 stages: buildir: 95.9993ms, U1000: 7.9972ms"
level=info msg="[runner] processing took 0s with stages: skip_files: 0s, exclude: 0s, diff: 0s, max_per_file_from_linter: 0s, cgo: 0s, identifier_marker: 0s, nolint: 0s, uniq_by_line: 0s, source_code: 0s, skip_dirs: 0s, max_from_linter: 0s, filename_unadjuster: 0s, autogenerated_exclude: 0s, exclude-rules: 0s, max_same_issues: 0s, path_shortener: 0s, path_prettifier: 0s"
level=info msg="[runner] linters took 5.2698221s with stages: goanalysis_metalinter: 5.0468471s, unused: 205.9735ms"
level=error msg="Running error: gofmt: can't extract issues from gofmt diff output \"\": got no diffs from patch parser: []"
level=info msg="Memory: 62 samples, avg is 331.6MB, max is 554.7MB"
level=info msg="Execution took 6.0514173s"

Diff tool for Windows was downloaded from https://www.wzw.tum.de/public-html/syring/win32/UnxUtilsDist.html
Tried also, https://sourceforge.net/projects/gnuwin32/ - same error.

There was similar issue here:
#307
So I tried gofmt with -d:

C:\Windows\System32>gofmt -d
  package main

^Z
diff -u <standard input>.orig <standard input>
--- <standard input>.orig       Fri May 29 12:07:57 2020
+++ <standard input>    Fri May 29 12:07:57 2020
@@ -1,2 +1 @@
-  package main
-
+package main

So I believe this time the linter can't parse output of gofmt. In case if you provide already formatted document, the output is:

gofmt -d
package main
^Z
**diff -u <standard input>.orig <standard input>**
@johny7 johny7 added the bug Something isn't working label May 29, 2020
@boring-cyborg
Copy link

boring-cyborg bot commented May 29, 2020

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

@johny7
Copy link
Author

johny7 commented May 29, 2020

Well, I downloaded goimports tool:

go get golang.org/x/tools/cmd/goimports
go: downloading golang.org/x/tools v0.0.0-20200528185414-6be401e3f76e
go: found golang.org/x/tools/cmd/goimports in golang.org/x/tools v0.0.0-20200528185414-6be401e3f76e
go: downloading golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4
go: golang.org/x/tools upgrade => v0.0.0-20200528185414-6be401e3f76e

And gofmt started magically to work..

@johny7 johny7 closed this as completed May 29, 2020
@okhowang
Copy link

I found the root reason is that:
goimports use diff -u command to output diff result,
and golangci-lint use github.com/sourcegraph/go-diff/diff to parse the diff result.

diff result should be some format like

diff --ruN a/oldname1 b/newname1
--- oldname1	2009-10-11 15:12:20.000000000 +0000
+++ newname1	2009-10-11 15:12:30.000000000 +0000
@@ -1,3 +1,9 @@
+This is an important
+notice! It should
+therefore be located at
+the beginning of this
+document!
+
 This part of the
 document has stayed the
 same from version to

notice the time format after filename

and on windows platform, we may have some strangy diff command.
in my case, it was diff bundled with neovim.
it output time format like below

--- a   Tue Mar 16 10:34:34 2021
+++ b Tue Mar 16 10:34:36 2021

so error is occured when parsing diff result

can't parse patch: parsing time \"Wed Mar 17 12:09:16 2021\" as \"2006-01-02 15:04:05 -0700\": cannot parse \"Wed Mar 17 12:09:16 2021\" as \"2006\"

and I use git's diff C:\Program Files\Git\usr\bin\diff.exe instead of vim's diff, and everything is OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants