go printout messy code

121 views
Skip to first unread message

Hill

unread,
Feb 15, 2012, 10:55:20 AM2/15/12
to golang-nuts
I am using the latest weekly go build, on windows7 Chinese Language
version.
I have a program like below,

func main(){
_, err := os.Open("none-exist-file")
if err != nil{
fmt.Println(err)
}
}

after building it and run, it execute like:
open none-exist-file: 绯荤粺鎵句笉鍒版寚瀹氱殑鏂囦欢銆?

Why these messy code is printed out? How to solve this?
Thanks!

Ian Lance Taylor

unread,
Feb 15, 2012, 11:50:04 AM2/15/12
to Hill, golang-nuts
Hill <zhub...@gmail.com> writes:

The "open none-exist-file" comes from the Go library. The rest of the
characters (which I can not read) come from your OS. When you build the
Go distribution, it uses the strerror function to gather the standard OS
error messages. In your case, it got Chinese messages. Those messages
are then built into the Go libraries for use when printing system
errors.

This is all definitely rather awkward and will need better handling at
some point.

Ian

minux

unread,
Feb 15, 2012, 12:01:59 PM2/15/12
to Ian Lance Taylor, Hill, golang-nuts
I think Hill is complaining about the error message being completely unreadable.
Should be a encoding problem, I will look into it when I get to a Windows machine.

Paul Ruane

unread,
Feb 15, 2012, 12:28:02 PM2/15/12
to golang-nuts
On Feb 15, 5:01 pm, minux <minux...@gmail.com> wrote:
> I think Hill is complaining about the error message being completely
> unreadable.

"The system dirty Bai Ga Qin LIU version specified Yang Jing file."

Looks perfectly good to me ;).

peterGo

unread,
Feb 15, 2012, 4:34:52 PM2/15/12
to golang-nuts
Hill,

It looks like this issue: the use of localized error text on Windows.

Issue 1834: doc/progs/helloworld3 test fails on localized version of
Windows.
http://code.google.com/p/go/issues/detail?id=1834

Peter

peterGo

unread,
Feb 15, 2012, 4:43:37 PM2/15/12
to golang-nuts
Ian,

Issue 1834: doc/progs/helloworld3 test fails on localized version of
Windows.
http://code.google.com/p/go/issues/detail?id=1834

Peter

On Feb 15, 11:50 am, Ian Lance Taylor <i...@google.com> wrote:

brainman

unread,
Feb 15, 2012, 6:05:56 PM2/15/12
to golan...@googlegroups.com
I suspect the problem you are seeing is with the way your console display text. If so, it has been discussed before http://goo.gl/fQeKI.

As Ian said, go syscall package uses system error messages in "your system default language" - see windows (Errno).Error implementation in $GOROOT/src/pkg/syscall/syscall_windows.go. We call Windows FormatMessage api with dwLanguageId parameter set to 0. We could try and change this bit of code to force everyone to use English error messages. I do not know if it is better solution.

Alex

minux

unread,
Feb 16, 2012, 6:28:31 AM2/16/12
to brainman, golan...@googlegroups.com
On Thu, Feb 16, 2012 at 7:05 AM, brainman <alex.b...@gmail.com> wrote:
I suspect the problem you are seeing is with the way your console display text. If so, it has been discussed before http://goo.gl/fQeKI.

As Ian said, go syscall package uses system error messages in "your system default language" - see windows (Errno).Error implementation in $GOROOT/src/pkg/syscall/syscall_windows.go. We call Windows FormatMessage api with dwLanguageId parameter set to 0. We could try and change this bit of code to force everyone to use English error messages. I do not know if it is better solution.
I think this is the correct route to go, and this CL http://codereview.appspot.com/5673068 addresses that.
IMO, we already use English error messages everywhere, so it is completely reasonable to force Windows use that
and avoid the encoding problem (though we should address it at a latter stage).
Reply all
Reply to author
Forward
0 new messages