From 25cd181c9f096e20d41ffaddd0587f760c65717a Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 15 May 2023 15:32:38 +1000 Subject: [PATCH] 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 --- qt/aqt/mediasrv.py | 6 ++++-- ts/import-csv/index.ts | 22 ++++++++++++++++------ ts/lib/proto.ts | 7 +++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index c46aef4bf..92f20a328 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -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 diff --git a/ts/import-csv/index.ts b/ts/import-csv/index.ts index a723f2ee4..d0999089d 100644 --- a/ts/import-csv/index.ts +++ b/ts/import-csv/index.ts @@ -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 { 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(); diff --git a/ts/lib/proto.ts b/ts/lib/proto.ts index 734bb06c3..d11b04645 100644 --- a/ts/lib/proto.ts +++ b/ts/lib/proto.ts @@ -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>, 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);