Skip to content

Commit a0eceda

Browse files
Rename InvalidEncodingErr to ErrInvalidEncoding
1 parent 703a04e commit a0eceda

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

decoder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewDecoder(r io.Reader) *Decoder {
2121

2222
// ReadField reads a single line from the stream and parses it as a field. A
2323
// complete event is signalled by an empty key and value. The returned error
24-
// may either be an error from the stream, or an InvalidEncodingErr if the
24+
// may either be an error from the stream, or an ErrInvalidEncoding if the
2525
// value is not valid UTF-8.
2626
func (d *Decoder) ReadField() (field string, value []byte, err error) {
2727
var buf []byte
@@ -57,7 +57,7 @@ func (d *Decoder) ReadField() (field string, value []byte, err error) {
5757
}
5858

5959
if !utf8.ValidString(field) || !utf8.Valid(value) {
60-
err = InvalidEncodingErr
60+
err = ErrInvalidEncoding
6161
}
6262

6363
return

decoder_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func TestDecoderReadField(t *testing.T) {
2828
{"id:1", "id", []byte("1"), nil},
2929
{"id: 1", "id", []byte("1"), nil},
3030
{"data: " + longLine(), "data", []byte(longLine()), nil},
31-
{"\xFF\xFE\xFD", "\xFF\xFE\xFD", nil, InvalidEncodingErr},
32-
{"data: \xFF\xFE\xFD", "data", []byte("\xFF\xFE\xFD"), InvalidEncodingErr},
31+
{"\xFF\xFE\xFD", "\xFF\xFE\xFD", nil, ErrInvalidEncoding},
32+
{"data: \xFF\xFE\xFD", "data", []byte("\xFF\xFE\xFD"), ErrInvalidEncoding},
3333
}
3434

3535
for i, tt := range table {

encoder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ func (e *Encoder) Flush() error {
4343

4444
// WriteField writes an event field to the connection. If the provided value
4545
// contains newlines, multiple fields will be emitted. If the returned error is
46-
// not nil, it will be either InvalidEncodingErr or an error from the
46+
// not nil, it will be either ErrInvalidEncoding or an error from the
4747
// connection.
4848
func (e *Encoder) WriteField(field string, value []byte) error {
4949
if !utf8.ValidString(field) || !utf8.Valid(value) {
50-
return InvalidEncodingErr
50+
return ErrInvalidEncoding
5151
}
5252

5353
for _, line := range bytes.Split(value, []byte{'\n'}) {

encoder_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ func TestWriteField(t *testing.T) {
1414
}{
1515
{"data", []byte("data"), "data: data\n", nil},
1616
{"data", nil, "data\n", nil},
17-
{"\xFF\xFE\xFD", nil, "", InvalidEncodingErr},
18-
{"data", []byte("\xFF\xFE\xFD"), "", InvalidEncodingErr},
17+
{"\xFF\xFE\xFD", nil, "", ErrInvalidEncoding},
18+
{"data", []byte("\xFF\xFE\xFD"), "", ErrInvalidEncoding},
1919
{"data", []byte("a\nb\nc\n"), "data: a\ndata: b\ndata: c\ndata\n", nil},
2020
{"data", []byte("a\r\nb\r\nc"), "data: a\ndata: b\ndata: c\n", nil},
2121
}

eventsource.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ var (
1717
// reopened.
1818
ErrClosed = errors.New("closed")
1919

20-
// InvalidEncodingErr is returned by Encoder and Decoder when invalid UTF-8
20+
// ErrInvalidEncoding is returned by Encoder and Decoder when invalid UTF-8
2121
// event data is encountered.
22-
InvalidEncodingErr = errors.New("invalid UTF-8 sequence")
22+
ErrInvalidEncoding = errors.New("invalid UTF-8 sequence")
2323
)
2424

2525
// An Event is a message can be written to an event stream and read from an
@@ -118,7 +118,7 @@ func (es *EventSource) Read() (Event, error) {
118118

119119
err := es.dec.Decode(&e)
120120

121-
if err == InvalidEncodingErr {
121+
if err == ErrInvalidEncoding {
122122
continue
123123
}
124124

0 commit comments

Comments
 (0)