mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
Ensure that LocalizedError are returned by parsers
This commit is contained in:
parent
557cf9c21d
commit
0e6717b7c8
15 changed files with 71 additions and 30 deletions
|
@ -6,10 +6,11 @@ package atom
|
|||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
"io"
|
||||
|
||||
"github.com/miniflux/miniflux2/errors"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
|
||||
"golang.org/x/net/html/charset"
|
||||
)
|
||||
|
||||
|
@ -21,7 +22,7 @@ func Parse(data io.Reader) (*model.Feed, error) {
|
|||
|
||||
err := decoder.Decode(atomFeed)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to parse Atom feed: %v\n", err)
|
||||
return nil, errors.NewLocalizedError("Unable to parse Atom feed: %v", err)
|
||||
}
|
||||
|
||||
return atomFeed.Transform(), nil
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux2/errors"
|
||||
)
|
||||
|
||||
func TestParseAtomSample(t *testing.T) {
|
||||
|
@ -317,3 +319,15 @@ func TestParseEntryWithEnclosures(t *testing.T) {
|
|||
t.Errorf("Incorrect enclosure length, got: %d", feed.Entries[0].Enclosures[1].Size)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseInvalidXml(t *testing.T) {
|
||||
data := `garbage`
|
||||
_, err := Parse(bytes.NewBufferString(data))
|
||||
if err == nil {
|
||||
t.Error("Parse should returns an error")
|
||||
}
|
||||
|
||||
if _, ok := err.(errors.LocalizedError); !ok {
|
||||
t.Error("The error returned must be a LocalizedError")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,10 @@ package json
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
"io"
|
||||
|
||||
"github.com/miniflux/miniflux2/errors"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
)
|
||||
|
||||
// Parse returns a normalized feed struct.
|
||||
|
@ -16,7 +17,7 @@ func Parse(data io.Reader) (*model.Feed, error) {
|
|||
jsonFeed := new(JsonFeed)
|
||||
decoder := json.NewDecoder(data)
|
||||
if err := decoder.Decode(&jsonFeed); err != nil {
|
||||
return nil, fmt.Errorf("Unable to parse JSON Feed: %v", err)
|
||||
return nil, errors.NewLocalizedError("Unable to parse JSON Feed: %v", err)
|
||||
}
|
||||
|
||||
return jsonFeed.Transform(), nil
|
||||
|
|
|
@ -9,6 +9,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux2/errors"
|
||||
)
|
||||
|
||||
func TestParseJsonFeed(t *testing.T) {
|
||||
|
@ -343,3 +345,15 @@ func TestParseTruncateItemTitle(t *testing.T) {
|
|||
t.Errorf("Incorrect entry title, got: %s", feed.Entries[0].Title)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseInvalidJSON(t *testing.T) {
|
||||
data := `garbage`
|
||||
_, err := Parse(bytes.NewBufferString(data))
|
||||
if err == nil {
|
||||
t.Error("Parse should returns an error")
|
||||
}
|
||||
|
||||
if _, ok := err.(errors.LocalizedError); !ok {
|
||||
t.Error("The error returned must be a LocalizedError")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ package rss
|
|||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/miniflux/miniflux2/errors"
|
||||
"github.com/miniflux/miniflux2/model"
|
||||
|
||||
"golang.org/x/net/html/charset"
|
||||
|
@ -22,7 +22,7 @@ func Parse(data io.Reader) (*model.Feed, error) {
|
|||
|
||||
err := decoder.Decode(feed)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse RSS feed: %v", err)
|
||||
return nil, errors.NewLocalizedError("Unable to parse RSS feed: %v", err)
|
||||
}
|
||||
|
||||
return feed.Transform(), nil
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/miniflux/miniflux2/errors"
|
||||
)
|
||||
|
||||
func TestParseRss2Sample(t *testing.T) {
|
||||
|
@ -541,4 +543,8 @@ func TestParseInvalidXml(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Error("Parse should returns an error")
|
||||
}
|
||||
|
||||
if _, ok := err.(errors.LocalizedError); !ok {
|
||||
t.Error("The error returned must be a LocalizedError")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue