Skip to content

cmd/compile: confusing error message for a bad rune value, eg. '\xe4\xb8\x96' #20343

Closed

Description

@gbulmer

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

golang.org goplayground (1.8 I believe)

What operating system and processor architecture are you using (go env)?

I am using go playground from Firefox.

However for completeness:
GOARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
Firefox 53.0.2 (64-bit)

What did you do?

https://play.golang.org/p/NtvSPO4xx7

What did you expect to see?

An error message like:
"Badly formed Rune" or "Bad rune value" maybe even
"runes with values larger than 255, 0xFF, can't be defined using multiple \xhh values"

What did you see instead?

tmp/sandbox523565836/main.go:5: missing '
tmp/sandbox523565836/main.go:5: illegal character U+005C '\'
tmp/sandbox523565836/main.go:5: syntax error: unexpected xb8 at end of statement
tmp/sandbox523565836/main.go:5: newline in character literal

Issue Explanation/Justification

I think the Go compilers error messages are unnecessarily unhelpful or confusing.

The source doesn't look like there is a "missing ' ", it looks like there are a matching pair of single quotes.
The character U+005C '\' is legal in rune values, so that seems confusing.
In this example, the value xb8 is apparently in the middle of the rune, and so "syntax error: unexpected xb8 at end of statement" seems confusing.
The line doesn't look like there is a "newline in character literal".

A plausible behaviour might be to 'collect' all the characters up to and including an unescaped closing single quote (on the same line, and before a '//' comment mark), and treat all of those characters as part of the bad rune value.

Activity

  1. changed the title [-]Confusing Go compiler error message for a bad rune value, eg. '\xe4\xb8\x96'[/-] [+]cmd/compile: confusing error message for a bad rune value, eg. '\xe4\xb8\x96'[/+] on May 13, 2017
  2. ALTree commented on May 13, 2017

    @ALTree
    Member

    For reference, go/types prints

    runes.go:5:9: illegal rune literal
    

    We could mimic go/types behaviour. I have no idea how much work would be needed, so leaving it to others to decide if it's worth it.

  3. added
    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.
    on May 13, 2017
  4. added this to the Go1.10 milestone on May 13, 2017
  5. gbulmer commented on May 13, 2017

    @gbulmer
    Author

    I'd be satisfied with "illegal rune literal". One message, terse, accurate.

  6. gbulmer commented on May 13, 2017

    @gbulmer
    Author

    As an aside ...
    Is their a 'place' explaining all of the Go compilers error messages? My search didn't find it.
    It would be nice to have all Go compiler error messages along with a brief explanation of a possible cause of the error in a web-searchable place.
    I paste error messages from software into a web browser's search box, but in this case it didn't find much help. Sometimes stackoverflow is helpful, but not in this case.
    Explaining compiler error-messages might be a straightforward, well-bounded, activity to ask the Developer Experience Working Group to solve. The result could be helpful for new or occasional Go programmers, and so help them climb the learning curve more quickly and effectively.
    Further, if the 'place' had some authority or evidence of good quality, it might be the 'go to' place.

  7. gbulmer commented on May 13, 2017

    @gbulmer
    Author

    I apologise for not understanding this, but why add it to Go1.10 milestone? Didn't that happened years ago?

  8. ALTree commented on May 13, 2017

    @ALTree
    Member

    Is their a 'place' explaining all of the Go compilers error messages

    I don't think there is. I know Rust has something like that; and I agree that it could be nice to have something similar (even though Go is a simpler language and error messages usually are easy to understand; I rarely see people puzzled by a compiler error when programming in Go).

    Explaining compiler error-messages might be a straightforward, well-bounded, activity to ask the Developer Experience Working Group to solve

    I agree. You could ask for this on their mailing list. I don't think it's "straightforward", though. Doing this (and doing it well) will require a fair amount of effort.

    I apologise for not understanding this, but why add it to Go1.10 milestone? Didn't that happened years ago?

    The dot in the versioning number is not a decimal point, i.e. 1.10 is not 1.1. The sequence goes 1.1, 1.2, ..., 1.9, 1.10, 1.11, etc...

    The next go version will be go1.9, and then we'll have go1.10. I can't assign this issue to the 1.9 milestone because the go1.9 development phase is finished (we're now in a code freeze); so this will be likely considered for go1.10 (unless someone decides that this is critical and needs to be fixed for go1.9).

  9. gbulmer commented on May 13, 2017

    @gbulmer
    Author

    Thank you for your very swift, clear and useful responses.

    I'll think about asking on the mailing list. When I do, I have a small, but hopefully useful, additional idea.

    I'd understood the 'dot' in the version is not a decimal point.
    I hadn't known milestone names don't align with Go versions. So that is helpful to know.

    It seems a very low-priority to have version and milestone names align. I imagine retaining flexibility to have them be different probably significantly outweighs any small gains.

  10. self-assigned this
    on May 15, 2017
  11. modified the milestones: Go1.9, Go1.10 on May 15, 2017
  12. griesemer commented on May 15, 2017

    @griesemer
    Contributor

    Marking for 1.9 - easy enough to fix.

  13. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    and removed
    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.
    on May 15, 2017
  14. griesemer commented on May 15, 2017

    @griesemer
    Contributor

    I'm going to close this. The 1.9 compiler already produces a nice error message. For

    $ cat x.go
    package main
    
    func main() {
    	r20 := '\xe4\xb8\x96'
    }
    

    we get

    $ go tool compile x.go
    x.go:4:9: invalid character literal (more than one character)
    

    That is, this is fixed in the latest tools.
    The go playground will be updated to 1.9 once 1.9 is released.

  15. locked and limited conversation to collaborators on May 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions