ripose-jp/Memento

{audio} should be empty if unreachable

precondition opened this issue · 1 comments

If none of the audio sources for word pronunciations are reachable (e.g. internet is disabled), the {audio} marker gets filled with a very long error message like:

HTTPConnectionPool(host='assets.languagepod101.com', port=80): 
Max retries exceeded with url: 
/dictionary/japanese/audiomp3.php?kanji=%E6%8C%87%E6%8F%AE%E5%AE%98&kana=%E3%81%97%E3%81%8D%E3%81%8B%E3%82%93 
(Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7fa010e4b550>: 
Failed to resolve 'assets.languagepod101.com' ([Errno -2] 名前またはサービスが不明です)"))

which results in ugly Anki cards like this:
image

What I find interesting is that this error message differs from the one we obtain in src/audio/audioplayer.cpp line 163:

    connect(reply, &QNetworkReply::finished,  this,
        [=] {
            QTemporaryFile *file = nullptr;
            bool res = false;

            if (reply->error() != QNetworkReply::NetworkError::NoError)
            {
                qDebug() << reply->errorString(); // <----------------------
                goto cleanup;
            }

which says "Host assets.languagepod101.com not found"

I'd much rather get an empty {audio} marker than one filled with error messages.

I agree, but this is an AnkiConnect issue. It isn't fixable in Memento unless it pre-fetches audio always before adding a note. It should be pretty trivial to wrap AnkiConnect exceptions in <!-- --> so they don't appear on card. I'd recommend making a PR to AnkiConnect, since FooSoft is good about getting PRs merged quickly.

I'll leave it to you since I know you're a capable programmer and it's low hanging fruit. If you want me to do it instead though, let me know.