Skip to content

Commit

Permalink
Ignore error messages from anki-connect guiBrowse actions
Browse files Browse the repository at this point in the history
If a guiBrowse action fails, the rest of the app can still work, you
just might risk your card not updating if you have it open in the
browser, similar to when you have the "Do not update Anki browser"
option selected.

For #32 however, you don't even risk that by ignoring the error message,
so there's no downsides to ignoring it. Just log the error and move on.
  • Loading branch information
soamsy committed Aug 11, 2021
1 parent 2a7046f commit 791ad32
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions extension/bg/js/anki.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,28 @@ class AnkiConnect {
}

async showNoCardsInGui() {
return await this._invoke('guiBrowse', {query: "nid:1 nid:2"})
return await this.guiBrowse({query: "nid:1 nid:2"})
}

async showCurrentDeckInGui() {
var deck = this._settings.ankiDeck || "current";
return await this._invoke('guiBrowse', {query: `"deck:${deck}"`})
return await this.guiBrowse({query: `"deck:${deck}"`})
}

async runCustomBrowserQuery(query) {
return await this._invoke('guiBrowse', {query: query})
return await this.guiBrowse({query: query})
}

async showNoteInGui(noteId) {
return await this._invoke('guiBrowse', {query: "nid:" + noteId})
return await this.guiBrowse({query: "nid:" + noteId})
}

async guiBrowse(params) {
try {
return await this._invoke('guiBrowse', params)
} catch (e) {
console.warn("Ignoring error from Anki: " + e.message);
}
}

async _invoke(action, params) {
Expand Down

0 comments on commit 791ad32

Please sign in to comment.