Show an error pop-up when csv import screen fails to load

https://forums.ankiweb.net/t/windows-10-2-1-62-qt6-blank-import-window/30231
This commit is contained in:
Damien Elmes 2023-05-15 15:32:38 +10:00
parent 5f40fd6083
commit 25cd181c9f
3 changed files with 27 additions and 8 deletions

View file

@ -516,9 +516,11 @@ def _extract_collection_post_request(path: str) -> DynamicRequest | NotFound:
response.headers["Content-Type"] = "application/binary"
else:
response = flask.make_response("", HTTPStatus.NO_CONTENT)
except:
except Exception as exc:
print(traceback.format_exc())
response = flask.make_response("", HTTPStatus.INTERNAL_SERVER_ERROR)
response = flask.make_response(
str(exc), HTTPStatus.INTERNAL_SERVER_ERROR
)
return response
return wrapped

View file

@ -5,6 +5,7 @@ import "./import-csv-base.scss";
import { ModuleName, setupI18n } from "@tslib/i18n";
import { checkNightMode } from "@tslib/nightmode";
import type { ImportExport, Notetypes } from "@tslib/proto";
import { Decks, decks as decksService, empty, notetypes as notetypeService } from "@tslib/proto";
import ImportCsvPage from "./ImportCsvPage.svelte";
@ -32,12 +33,21 @@ const i18n = setupI18n({
export async function setupImportCsvPage(path: string): Promise<ImportCsvPage> {
const gettingMetadata = getCsvMetadata(path);
const [notetypes, decks, metadata] = await Promise.all([
gettingNotetypes,
gettingDecks,
gettingMetadata,
i18n,
]);
let notetypes: Notetypes.NotetypeNames;
let decks: Decks.DeckNames;
let metadata: ImportExport.CsvMetadata;
try {
[notetypes, decks, metadata] = await Promise.all([
gettingNotetypes,
gettingDecks,
gettingMetadata,
i18n,
]);
} catch (err) {
alert(err);
throw (err);
}
checkNightMode();

View file

@ -27,6 +27,8 @@ export { Cards, Collection, Decks, Generic, Notes };
export const empty = Generic.Empty.create();
export class InternalError extends Error {}
async function serviceCallback(
method: rpc.ServiceMethod<Message<any>, Message<any>>,
requestData: Uint8Array,
@ -45,6 +47,11 @@ async function serviceCallback(
body: requestData,
});
if (result.status == 500) {
callback(new InternalError(await result.text()), null);
return;
}
const blob = await result.blob();
const respBuf = await new Response(blob).arrayBuffer();
const uint8Array = new Uint8Array(respBuf);