encoding/json: Decoder.Token: on error SyntaxError.Offset is 0 #22478
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.9.2 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Markus/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bf/kbhmwc8j7nx3kjb285knl23c0000gn/T/go-build616159285=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
What did you do?
Process a file with JSON as a stream use json.Decoder.Token.
I try to use the SyntraxError.Offset to determine the line+pos of the error, for feedback to the user.
Minimal example:
https://play.golang.org/p/qPF2KKaESe
package main
import (
"fmt"
"encoding/json"
"strings"
)
func main() {
dec := json.NewDecoder(strings.NewReader(
{"foo": "bar"error}
))}
What did you expect to see?
I expect SyntaxError.Offset to be the byte offset into the Reader passed to DecoderNew.
What did you see instead?
It seems that the method Decoder.Token in the json package returns an SyntaxError with Offset always set to 0.
The text was updated successfully, but these errors were encountered: