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

cmd/compile: improve go compiler's syntax error message style #39274

Closed
delata opened this issue May 27, 2020 · 8 comments
Closed

cmd/compile: improve go compiler's syntax error message style #39274

delata opened this issue May 27, 2020 · 8 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@delata
Copy link

delata commented May 27, 2020

If i take a look at GCC 's error massage, i see that they are very user friendly and descriptive.
Also provide suggestions how to fix the error.

I wish Go compiler will have this features.

try helloworld on Go and GCC with syntax error. to understand what i am saying

thanks.

@andybons andybons changed the title improve go compiler's syntax error massage style cmd/compile: improve go compiler's syntax error massage style May 27, 2020
@andybons
Copy link
Member

While I understand the sentiment and agree that better error messages are a good thing for users, this issue doesn’t have a concrete proposal of what, precisely, should be improved. Without more actionable examples and proposed changes, this is difficult to act upon.

What, precisely, would you like to see changed?

@andybons andybons added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 27, 2020
@mdempsky mdempsky changed the title cmd/compile: improve go compiler's syntax error massage style cmd/compile: improve go compiler's syntax error message style May 27, 2020
@delata
Copy link
Author

delata commented May 27, 2020

make it more like gcc. Also rustc looks good.
you know what mean. make it good, not bloated.

@ianlancetaylor
Copy link
Contributor

@delata No, we don't know what you mean. We can guess, but experience tells me that our guess will not be what you expect. You know what you want. There is no reason to make us guess.
Please show us some examples. Thanks.

@delata
Copy link
Author

delata commented May 28, 2020

try, helloworld with syntax error.

@delata
Copy link
Author

delata commented May 28, 2020

i am unable to communicate my thought properly. sorry. English isn't my native language. currently i don't have access to a computer. i am writing this from a phone.

What you think about current error message style. are they good? if not, then discuss with core team and improve.

please.

this is the only reason i can't learn Go. I make a lot of syntax error and when i try to compile Go compiler don't give any good suggestion.
But with gcc it's very easy.
I want to learn Go.
please make the error message better, more helpful, user friendly.
thanks.

@ianlancetaylor
Copy link
Contributor

Show us exactly what you did. Show us exactly what happened. Show us what you want to happen instead.

Otherwise we cannot help you. Sorry.

@andybons
Copy link
Member

andybons commented May 28, 2020

Given two “hello, world” examples with syntax errors (in C and Go, respectively):

C program:

#include <stdio.h>

int main() {
  printf("hello, world!\n);
  return 0;
}

gcc error:

main.c:4:10: warning: missing terminating '"' character [-Winvalid-pp-token]
  printf("hello, world!\n);
         ^
main.c:4:10: error: expected expression
main.c:6:2: error: expected '}'
}
 ^
main.c:3:12: note: to match this '{'
int main() {
           ^
1 warning and 2 errors generated.

Go program:

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello, playground)
}

gc error:

./prog.go:8:33: newline in string
./prog.go:8:33: syntax error: unexpected newline, expecting comma or )

The warning is arguably more helpful, but both errors seem very similar. Note that Go doesn’t have warnings. If we interpret the warning as an error, then how granular is this specific request? Show a ^ under the offending line? Color-code the output? Show an error when there is no terminating quote in a string? That’s just for one class of errors.

We are sensitive to the sentiment you’re attempting to communicate, but the details matter. We can’t read your mind and are empathetic to the challenges that being a non-native English speaker presents, but without concrete requirements it’s very difficult for us to move forward. Additionally, asking us to run different compilers and compare output ourselves instead of running the commands yourself can be interpreted as you wanting others to do an outsized amount of work to, again, end up with a potential solution that doesn’t fit your requirements.

Closing for now. If you have more concrete requirements you’d like to communicate, feel free to do so. Thanks.

@blois
Copy link

blois commented Oct 23, 2020

Compare to Typescropt:

class Foo {
  doSomething() {
  }
}

new Foo().doSomethin()

Yields:

test.ts:4:11 - error TS2551: Property 'doSomethin' does not exist on type 'Foo'. Did you mean 'doSomething'?

5 new Foo().doSomethin()
            ~~~~~~~~~~

  test.ts:3:3
    3   doSomething() {
        ~~~~~~~~~~~
    'doSomething' is declared here.

Compare to Go:

type Foo struct {
}

func(f Foo) doSomething() {
}

func main() {
	f := Foo{}
	f.doSomethin()
}

yields:

./prog.go:13:3: f.doSomethin undefined (type Foo has no field or method doSomethin)

There are a couple of things that I think make the TS version of this ergonomically better:

  • Not seen here, but it makes a big difference- TS uses colors to clearly differentiate source code filename from line numbers from code.
  • The error is shown clearly within the context of the source code.
  • The source code includes an underline indicating the range of the error.
  • For a simple typo, TS provides a useful 'did you mean' alternative. This is especially helpful when I make a typo in a long name and just can't see where the typo was because it clarifies that the issue was most likely just a typo.

@golang golang locked and limited conversation to collaborators Oct 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants