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

text/scanner: revert CL 19622? #15813

Closed
rsc opened this issue May 24, 2016 · 2 comments
Closed

text/scanner: revert CL 19622? #15813

rsc opened this issue May 24, 2016 · 2 comments

Comments

@rsc
Copy link
Contributor

rsc commented May 24, 2016

CL 19622 inserted a text/scanner prefix at the beginning of any error printed to standard error.

This was motivated by confusion on #14166 about where some output was coming from. But the fix seems to me a regression, at least in the case where the scanner knows the file name. If, say, a program like a compiler or assembler were using text/scanner to lex its input and using text/scanner's default error implementation (that is, not providing a custom error implementation), then previously an invocation reporting a lexical problem might look like:

$ myprogram foo.txt
foo.txt:10:12: illegal hexadecimal number
$

Now it looks like:

$ myprogram foo.txt
text/scanner: foo.txt:10:12: illegal hexadecimal number
$

I do understand that if the file name is not known, then this is confusing, as in #14166:

$ myprogram < foo.txt
10:12: illegal hexadecimal number
$

But perhaps the fix, if one must be made, would be to replace an empty file name with a pseudo-name like <input>, as in:

$ myprogram < foo.txt
<input>:10:12: illegal hexadecimal number
$

I think this form makes it clearer that 10:12 is an input position, without exposing an implementation detail (namely the use of text/scanner).

The critical point here is that the errors printed by text/scanner are expected by the users of text/scanner; they are a natural part of the operation of scanning input.

In contrast, in the rare case where a package prints a message to standard error to report an problem such as a consistency violation, that message is not unexpected and so a prefix is entirely appropriate.

I suggest text/scanner be changed to remove the new text/scanner prefix and possibly print <input> instead of an empty file name at the beginning of an error message (but not in Position.String, which might have other users).

@rsc rsc added this to the Go1.7Beta milestone May 24, 2016
@griesemer
Copy link
Contributor

Sure, sounds reasonable. Will address tomorrow.

@gopherbot
Copy link

CL https://golang.org/cl/23402 mentions this issue.

@golang golang locked and limited conversation to collaborators May 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants