Improve error when card has missing content (#1818)
This commit is contained in:
parent
7a1570885e
commit
d897fb553d
@ -368,12 +368,8 @@ class DisplayAnki {
|
|||||||
const {note, errors, requirements: outputRequirements} = await this._createNote(dictionaryEntry, mode, requirements);
|
const {note, errors, requirements: outputRequirements} = await this._createNote(dictionaryEntry, mode, requirements);
|
||||||
allErrors.push(...errors);
|
allErrors.push(...errors);
|
||||||
|
|
||||||
if (outputRequirements.length > 0) {
|
const error = this._getAddNoteRequirementsError(requirements, outputRequirements);
|
||||||
const error = new Error('The created card may not have some content');
|
if (error !== null) { allErrors.push(error); }
|
||||||
error.requirements = requirements;
|
|
||||||
error.outputRequirements = outputRequirements;
|
|
||||||
allErrors.push(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
let noteId = null;
|
let noteId = null;
|
||||||
let addNoteOkay = false;
|
let addNoteOkay = false;
|
||||||
@ -413,6 +409,29 @@ class DisplayAnki {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getAddNoteRequirementsError(requirements, outputRequirements) {
|
||||||
|
if (outputRequirements.length === 0) { return null; }
|
||||||
|
|
||||||
|
let count = 0;
|
||||||
|
for (const requirement of outputRequirements) {
|
||||||
|
const {type} = requirement;
|
||||||
|
switch (type) {
|
||||||
|
case 'audio':
|
||||||
|
case 'clipboardImage':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
++count;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count === 0) { return null; }
|
||||||
|
|
||||||
|
const error = new Error('The created card may not have some content');
|
||||||
|
error.requirements = requirements;
|
||||||
|
error.outputRequirements = outputRequirements;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
_showAnkiNoteErrors(errors) {
|
_showAnkiNoteErrors(errors) {
|
||||||
if (this._ankiNoteNotificationEventListeners !== null) {
|
if (this._ankiNoteNotificationEventListeners !== null) {
|
||||||
this._ankiNoteNotificationEventListeners.removeAllEventListeners();
|
this._ankiNoteNotificationEventListeners.removeAllEventListeners();
|
||||||
|
Loading…
Reference in New Issue
Block a user