From e2ebd1ff04af2899dcc0de9c9a28870b27c9e5c4 Mon Sep 17 00:00:00 2001 From: cosmic-snow <134004613+cosmic-snow@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:21:25 +0200 Subject: [PATCH] localdocs: fail fast on bad path, more detailed 'invalid' error (#2679) Signed-off-by: Cosmic Snow --- gpt4all-chat/database.cpp | 6 +++++- gpt4all-chat/qml/LocalDocsView.qml | 13 +++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gpt4all-chat/database.cpp b/gpt4all-chat/database.cpp index e899b1c7..02ab5364 100644 --- a/gpt4all-chat/database.cpp +++ b/gpt4all-chat/database.cpp @@ -844,6 +844,10 @@ bool Database::hasContent() int Database::openDatabase(const QString &modelPath, bool create, int ver) { + if (!QFileInfo(modelPath).isDir()) { + qWarning() << "ERROR: invalid download path" << modelPath; + return -1; + } if (m_db.isOpen()) m_db.close(); auto dbPath = u"%1/localdocs_v%2.db"_s.arg(modelPath).arg(ver); @@ -851,7 +855,7 @@ int Database::openDatabase(const QString &modelPath, bool create, int ver) return 0; m_db.setDatabaseName(dbPath); if (!m_db.open()) { - qWarning() << "ERROR: opening db" << m_db.lastError(); + qWarning() << "ERROR: opening db" << dbPath << m_db.lastError(); return -1; } return hasContent(); diff --git a/gpt4all-chat/qml/LocalDocsView.qml b/gpt4all-chat/qml/LocalDocsView.qml index fc9960b5..c8758604 100644 --- a/gpt4all-chat/qml/LocalDocsView.qml +++ b/gpt4all-chat/qml/LocalDocsView.qml @@ -82,11 +82,16 @@ Rectangle { visible: !LocalDocs.databaseValid Text { anchors.centerIn: parent - horizontalAlignment: Qt.AlignHCenter - text: qsTr("ERROR: The LocalDocs database is not valid.") + text: qsTr("

ERROR: The LocalDocs database cannot be accessed or is not valid.


" + + "Note: You will need to restart after trying any of the following suggested fixes.
" + + "
" + + "If the problem persists and there are any 'localdocs_v*.db' files present, as a last resort you can
" + + "try backing them up and removing them. You will have to recreate your collections, however.") color: theme.textErrorColor - font.bold: true - font.pixelSize: theme.fontSizeLargest + font.pixelSize: theme.fontSizeLarger } }