Less confusing wront type error messages

This commit is contained in:
Mattias Wadman
2019-11-01 00:25:12 +01:00
parent 042aba554c
commit 4bc99db15d
2 changed files with 8 additions and 8 deletions

View File

@ -319,9 +319,9 @@ func infoFromURL(ctx context.Context, rawURL string, options Options) (info Info
isPlaylist := info.Type == "playlist" || info.Type == "multi_video" isPlaylist := info.Type == "playlist" || info.Type == "multi_video"
switch { switch {
case options.Type == TypePlaylist && !isPlaylist: case options.Type == TypePlaylist && !isPlaylist:
return Info{}, nil, fmt.Errorf("not a playlist") return Info{}, nil, fmt.Errorf("is not a playlist")
case options.Type == TypeSingle && isPlaylist: case options.Type == TypeSingle && isPlaylist:
return Info{}, nil, fmt.Errorf("not a single") return Info{}, nil, fmt.Errorf("is not a single entry")
default: default:
// any type // any type
} }
@ -406,7 +406,7 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu
debugLog := result.Options.DebugLog debugLog := result.Options.DebugLog
if result.Info.Type == "playlist" || result.Info.Type == "multi_video" { if result.Info.Type == "playlist" || result.Info.Type == "multi_video" {
return nil, fmt.Errorf("is a playlist") return nil, fmt.Errorf("can't download a playlist")
} }
tempPath, tempErr := ioutil.TempDir("", "ydls") tempPath, tempErr := ioutil.TempDir("", "ydls")

View File

@ -233,22 +233,22 @@ func TestSubtitles(t *testing.T) {
} }
} }
func TestErrorNotAPlaylist(t *testing.T) { func TestErrorIsNotAPlaylist(t *testing.T) {
_, ydlResultErr := New(context.Background(), testVideoRawURL, Options{ _, ydlResultErr := New(context.Background(), testVideoRawURL, Options{
Type: TypePlaylist, Type: TypePlaylist,
DownloadThumbnail: false, DownloadThumbnail: false,
}) })
if ydlResultErr.Error() != "not a playlist" { if ydlResultErr.Error() != "is not a playlist" {
t.Errorf("expected is playlist error") t.Errorf("expected is playlist error")
} }
} }
func TestErrorNotASingle(t *testing.T) { func TestErrorIsNotASingleEntry(t *testing.T) {
_, ydlResultErr := New(context.Background(), playlistRawURL, Options{ _, ydlResultErr := New(context.Background(), playlistRawURL, Options{
Type: TypeSingle, Type: TypeSingle,
DownloadThumbnail: false, DownloadThumbnail: false,
}) })
if ydlResultErr.Error() != "not a single" { if ydlResultErr.Error() != "is not a single entry" {
t.Errorf("expected is playlist error") t.Errorf("expected is not a playlist error")
} }
} }