-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
encoding/json: SyntaxError does not have "json:" prefix #36221
Comments
I can submit a fix, just let me know if that's something it would be good to fix |
I assume you mean that their I'm not sure that the prefix should be part of the error value itself, though. If the error type is |
I've been thrown off by this before. |
Change https://golang.org/cl/263619 mentions this issue: |
I'm still not sure about this. Is there a precedent with other exported error types in the standard library whose Error method uses a prefix? It feels redundant for a json error to prepend its own package name. I also can't recall any other standard library error behaving this way, besides non-typed For example, the os errors use the operation or syscall as the prefix, so you get |
Every other named error in that package prepends the prefix:
SyntaxError is the only one that doesn't. I wasn't aware that this wasn't common practice across the standard library, if it isn't then maybe we should leave it as is. |
Ah, you're right, there's plenty of precedent in the same package. I wonder if we would break any existing valid programs, but I would imagine not. I'll go review. |
Change https://golang.org/cl/273747 mentions this issue: |
This reverts commit 6af088b. Reason for revert: Broke many tests inside Google which implies many tests were broken outside of Google as well. The tests may be brittle but still would require work to change and it's not clear it's worth the benefit. Updates #36221 Fixes #42675 Change-Id: Id3a14eb37e7119f5abe50e80dfbf120fdc44db72 Reviewed-on: https://go-review.googlesource.com/c/go/+/273747 Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> Trust: Joe Tsai <thebrokentoaster@gmail.com>
Re-opening. I still think this is worth doing in the future, but we may want to batch it with other small changes that may technically break users who depend on unspecified behavior. See #42675 |
It was my understanding that most errors created inside of a standard library package should be prefixed with the package name. For example, the error message for
sql.ErrNoRows
iserrors.New("sql: no rows in result set")
, noterrors.New("no rows in result set")
.Some errors in the
json
package are returned without a leading prefix. I noticed this because I hit one and it took some digging to figure out where in the codebase the error was actually coming from.These tests in scanner_test.go check that the error matches a SyntaxError without a leading prefix.
Is that right? Shouldn't those error messages have a leading "json:" prefix?
The text was updated successfully, but these errors were encountered: