numtide / treefmt

one CLI to format your repo [maintainers=@zimbatm,@brianmcgee]
https://treefmt.com
MIT License
602 stars 37 forks source link

No output when syntax errors in Go file #206

Closed renoire closed 1 year ago

renoire commented 1 year ago

I run the command in a dir where there's a go file which looks like this (the curly brace on a new line):

func main() 
{
    fmt.Println("hello world")
}

There's zero output, however I would expect it to forward the formatter error message to the console. Same with any other file contents not matching go, but having a .go extension.

zimbatm commented 1 year ago

I can reproduce the issue by changing the repo:

$ git diff
diff --git a/examples/go/main.go b/examples/go/main.go
index c048119..6e81588 100644
--- a/examples/go/main.go
+++ b/examples/go/main.go
@@ -2,6 +2,8 @@ package main

 import "fmt"

-func main() {
+func main()
+
+{
        fmt.Println("hello world")
 }
$ treefmt -C examples/go/

$ echo $?
1
$ gofmt examples/go/
examples/go/main.go:7:1: unexpected semicolon or newline before {

Treefmt should display the error

zimbatm commented 1 year ago

This changed in the last release. With treefmt v0.4.0:

$ treefmt
[INFO]: Error using formatter #go:
• [STDOUT]:

• [STDERR]:
/home/zimbatm/go/src/github.com/numtide/treefmt/examples/go/main.go:7:1: unexpected semicolon or newline before {

[ERR]: #go's formatter failed: exit status 2
zimbatm commented 1 year ago

@brianmcgee this behaviour changed in 897bf115b136eaa67fa79051465bc5c37d298a0e

brianmcgee commented 1 year ago

@zimbatm I can have a look later today

brianmcgee commented 1 year ago

Fix available #207

Copy paste error when switching the log framework. Default log level should be Warn not Off.