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

go/scanner: improve error message when a Go file is encoded as UCS-2 #71950

Closed
adonovan opened this issue Feb 25, 2025 · 4 comments
Closed

go/scanner: improve error message when a Go file is encoded as UCS-2 #71950

adonovan opened this issue Feb 25, 2025 · 4 comments
Assignees
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool

Comments

@adonovan
Copy link
Member

adonovan commented Feb 25, 2025

When a Windows user mistakenly creates a Go text file encoded as UCS-2 (i.e. UTF-16 2-byte encoding) the error message they see is "unexpected NUL", from the zero byte in the encoding of the first rune of the file (typically one of [ \n/p]). The scanner could issue a more helpful error: "encoding of file foo.go is UCS-2; Go requires UTF-8".

(The presence of a U+FEFF BOM is not by itself indicative of a UCS-2 encoding.)

See also golang/vscode-go#3690

@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Feb 25, 2025
@ianlancetaylor
Copy link
Member

ianlancetaylor commented Feb 25, 2025

See also #71872 .

@adonovan adonovan self-assigned this Feb 25, 2025
@adonovan

This comment has been minimized.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/652515 mentions this issue: go/scanner: report specific error for UCS-2 encoded files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool
Projects
None yet
Development

No branches or pull requests

4 participants