Skip to content

Should handle EOF correctly #214

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

Closed
cuigh opened this issue Dec 21, 2017 · 2 comments
Closed

Should handle EOF correctly #214

cuigh opened this issue Dec 21, 2017 · 2 comments

Comments

@cuigh
Copy link

cuigh commented Dec 21, 2017

Now jsoniter treat io.EOF as normal error, this is not compatible with stdlib, should return io.EOF instead of wrapping it.

[E]2017-12-21 11:40:56.809: server > decode failed: readObjectStart: expect { or n, but found , error found in #10 byte of ...|:["auxo"]}
|..., bigger context ...|service":"Test","method":"Hello"},"args":["auxo"]}
@taowen
Copy link
Contributor

taowen commented Dec 21, 2017

please provide your test code.

@cuigh
Copy link
Author

cuigh commented Dec 21, 2017

package jsoniter_test

import (
	"bytes"
	"encoding/json"
	"io"
	"testing"

	"github.com/cuigh/auxo/test/assert"
	"github.com/json-iterator/go"
)

func TestEOF1(t *testing.T) {
	var json = jsoniter.ConfigCompatibleWithStandardLibrary
	var s string
	err := json.NewDecoder(&bytes.Buffer{}).Decode(&s)
	assert.Equal(t, io.EOF, err)
}

func TestEOF2(t *testing.T) {
	var s string
	err := json.NewDecoder(&bytes.Buffer{}).Decode(&s)
	assert.Equal(t, io.EOF, err)
}

The first case TestEOF1 on the above will fail:

	json_test.go:17: Not equal: &errors.errorString{s:"EOF"} (expected) != &errors.errorString{s:"ReadString: expects \" or n, but found \x00, error found in #0 byte of ...||..., bigger context ...||..."} (actual)

@taowen taowen closed this as completed in 60a9df5 Dec 21, 2017
zhenzou pushed a commit to zhenzou/jsoniter that referenced this issue Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants