Better errors and error handling

Fix issue with ignore errors for playlists, now ignore
errors if we get info JSON with a non empty ID.
This commit is contained in:
Mattias Wadman
2019-11-05 00:45:14 +01:00
parent 77a906a487
commit 3b67f6a80c
2 changed files with 61 additions and 28 deletions

View File

@ -181,6 +181,20 @@ func TestPlaylist(t *testing.T) {
}
}
func TestTestUnsupportedURL(t *testing.T) {
defer leaktest.Check(t)()
_, ydlResultErr := New(context.Background(), "https://www.google.com", Options{})
if ydlResultErr == nil {
t.Errorf("expected unsupported url")
}
expectedErr := "Unsupported URL: https://www.google.com"
if ydlResultErr != nil && ydlResultErr.Error() != expectedErr {
t.Errorf("expected error %q got %q", expectedErr, ydlResultErr.Error())
}
}
func TestPlaylistWithPrivateVideo(t *testing.T) {
defer leaktest.Check(t)()
@ -233,22 +247,26 @@ func TestSubtitles(t *testing.T) {
}
}
func TestErrorIsNotAPlaylist(t *testing.T) {
func TestErrorNotAPlaylist(t *testing.T) {
defer leakChecks(t)()
_, ydlResultErr := New(context.Background(), testVideoRawURL, Options{
Type: TypePlaylist,
DownloadThumbnail: false,
})
if ydlResultErr.Error() != "is not a playlist" {
t.Errorf("expected is playlist error")
if ydlResultErr != ErrNotAPlaylist {
t.Errorf("expected is playlist error, got %s", ydlResultErr)
}
}
func TestErrorIsNotASingleEntry(t *testing.T) {
func TestErrorNotASingleEntry(t *testing.T) {
defer leakChecks(t)()
_, ydlResultErr := New(context.Background(), playlistRawURL, Options{
Type: TypeSingle,
DownloadThumbnail: false,
})
if ydlResultErr.Error() != "is not a single entry" {
t.Errorf("expected is not a playlist error")
if ydlResultErr != ErrNotASingleEntry {
t.Errorf("expected is single entry error, got %s", ydlResultErr)
}
}