Skip to content

Commit 4f662f6

Browse files
committed
fix(encryption): explain preflight failures with notebook context
1 parent 72dd15b commit 4f662f6

5 files changed

Lines changed: 83 additions & 11 deletions

File tree

changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changes
22
## Unreleased
33
* Fix note encryption failing with "Not found" when the notebook has an empty Git sync directory
4+
* Explain encryption preflight failures with notebook locations and localized guidance for unreadable sync metadata or conflicting key files
45
* Remove buffer reload logging and log external file changes only at debug level to avoid log-viewing feedback at normal log levels
56
* Keep the custom title bar Close icon visible on hover in Dreamy and Jadeite themes
67
* Match the United Entry icon color to the other main toolbar icons, including live theme changes

src/data/core/translations/vnote_ja.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5877,6 +5877,30 @@ This will re-scan all files and rebuild the metadata cache from the filesystem.<
58775877
<source>Encrypt Note</source>
58785878
<translation>ノートを暗号化</translation>
58795879
</message>
5880+
<message>
5881+
<source>Cannot check encryption key conflicts in the notebook's local Git sync data (vx_notebook/vx_sync). Check folder permissions and repair the local sync repository before retrying. Do not delete encryption.vne or Git history.</source>
5882+
<translation>ノートブックのローカル Git 同期データ(vx_notebook/vx_sync)の暗号鍵の競合を確認できません。フォルダーのアクセス権を確認し、ローカル同期リポジトリを修復してから再試行してください。encryption.vne や Git の履歴を削除しないでください。</translation>
5883+
</message>
5884+
<message>
5885+
<source>The notebook key file (vx_notebook/encryption.vne) has an unresolved sync conflict. Back up the notebook and resolve that conflict before retrying. Do not delete the key file or merge its contents as text.</source>
5886+
<translation>ノートブックの鍵ファイル(vx_notebook/encryption.vne)に未解決の同期競合があります。ノートブックをバックアップし、その競合を解決してから再試行してください。鍵ファイルを削除したり、内容をテキストとしてマージしたりしないでください。</translation>
5887+
</message>
5888+
<message>
5889+
<source>Master-password source notebook: %1</source>
5890+
<translation>マスターパスワードの提供元ノートブック: %1</translation>
5891+
</message>
5892+
<message>
5893+
<source>Could not prepare note encryption.
5894+
5895+
Notebook: %1
5896+
5897+
%2</source>
5898+
<translation>ノートの暗号化を準備できませんでした。
5899+
5900+
ノートブック: %1
5901+
5902+
%2</translation>
5903+
</message>
58805904
<message>
58815905
<location line="-60"/>
58825906
<source>Select notes from one notebook at a time.</source>

src/data/core/translations/vnote_zh_CN.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5877,6 +5877,30 @@ This will re-scan all files and rebuild the metadata cache from the filesystem.<
58775877
<source>Encrypt Note</source>
58785878
<translation>加密笔记</translation>
58795879
</message>
5880+
<message>
5881+
<source>Cannot check encryption key conflicts in the notebook's local Git sync data (vx_notebook/vx_sync). Check folder permissions and repair the local sync repository before retrying. Do not delete encryption.vne or Git history.</source>
5882+
<translation>无法检查笔记本本地 Git 同步数据(vx_notebook/vx_sync)中的加密密钥冲突。请检查文件夹权限并修复本地同步仓库后重试。请勿删除 encryption.vne 或 Git 历史记录。</translation>
5883+
</message>
5884+
<message>
5885+
<source>The notebook key file (vx_notebook/encryption.vne) has an unresolved sync conflict. Back up the notebook and resolve that conflict before retrying. Do not delete the key file or merge its contents as text.</source>
5886+
<translation>笔记本密钥文件(vx_notebook/encryption.vne)存在未解决的同步冲突。请先备份笔记本并解决该冲突,然后重试。请勿删除密钥文件或以文本方式合并其内容。</translation>
5887+
</message>
5888+
<message>
5889+
<source>Master-password source notebook: %1</source>
5890+
<translation>主密码来源笔记本:%1</translation>
5891+
</message>
5892+
<message>
5893+
<source>Could not prepare note encryption.
5894+
5895+
Notebook: %1
5896+
5897+
%2</source>
5898+
<translation>无法准备笔记加密。
5899+
5900+
笔记本:%1
5901+
5902+
%2</translation>
5903+
</message>
58805904
<message>
58815905
<location line="-60"/>
58825906
<source>Select notes from one notebook at a time.</source>

src/widgets/notebookexplorer2.cpp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,33 @@ VxCoreError NotebookExplorer2::prepareNotebookEncryption(const QString &p_notebo
237237
p_errorMessage = tr("The note encryption services are unavailable.");
238238
return VXCORE_ERR_NOT_INITIALIZED;
239239
}
240-
const auto fail = [&](VxCoreError p_error, const QString &p_message = QString()) {
241-
p_errorMessage = !p_message.isEmpty() ? p_message
242-
: p_error == VXCORE_ERR_ENCRYPTION_AUTH_FAILED
243-
? tr("Unable to unlock: incorrect password or damaged key data")
244-
: QString::fromUtf8(vxcore_error_message(p_error));
240+
const auto fail = [&](VxCoreError p_error, const QString &p_message = QString(),
241+
const QString &p_sourceId = QString()) {
242+
QString message;
243+
if (p_error == VXCORE_ERR_ENCRYPTION_SYNC_STATE) {
244+
message = tr("Cannot check encryption key conflicts in the notebook's local Git sync data "
245+
"(vx_notebook/vx_sync). Check folder permissions and repair the local sync "
246+
"repository before retrying. Do not delete encryption.vne or Git history.");
247+
} else if (p_error == VXCORE_ERR_SYNC_CONFLICT) {
248+
message = tr("The notebook key file (vx_notebook/encryption.vne) has an unresolved sync "
249+
"conflict. Back up the notebook and resolve that conflict before retrying. "
250+
"Do not delete the key file or merge its contents as text.");
251+
} else if (p_error == VXCORE_ERR_ENCRYPTION_AUTH_FAILED) {
252+
message = tr("Unable to unlock: incorrect password or damaged key data");
253+
} else {
254+
message = p_message.isEmpty() ? QString::fromUtf8(vxcore_error_message(p_error)) : p_message;
255+
}
256+
const auto location = [&](const QString &p_id) {
257+
const auto path = notebooks->buildAbsolutePath(p_id, QString());
258+
return path.isEmpty() ? p_id : QDir::toNativeSeparators(path);
259+
};
260+
QString notebook = location(p_notebookId);
261+
if (!p_sourceId.isEmpty() && p_sourceId != p_notebookId) {
262+
notebook +=
263+
QLatin1Char('\n') + tr("Master-password source notebook: %1").arg(location(p_sourceId));
264+
}
265+
p_errorMessage =
266+
tr("Could not prepare note encryption.\n\nNotebook: %1\n\n%2").arg(notebook, message);
245267
return p_error;
246268
};
247269
const auto unlock = [&](const QString &p_id, const QString &p_name) {
@@ -257,7 +279,9 @@ VxCoreError NotebookExplorer2::prepareNotebookEncryption(const QString &p_notebo
257279
passwordText.fill(QChar(0));
258280
passwordText.clear();
259281
p_progress.setLabelText(tr("Unlocking notebook..."));
260-
return m_viewAreaController->unlockNoteEncryption(p_id, password);
282+
const auto error = m_viewAreaController->unlockNoteEncryption(p_id, password);
283+
return error == VXCORE_OK || error == VXCORE_ERR_CANCELLED ? error
284+
: fail(error, QString(), p_id);
261285
};
262286

263287
VxCoreError statusError = VXCORE_OK;
@@ -272,8 +296,7 @@ VxCoreError NotebookExplorer2::prepareNotebookEncryption(const QString &p_notebo
272296
const QString name = notebooks->getNotebookConfig(p_notebookId)
273297
.value(QLatin1String(vxcore::kJsonKeyName))
274298
.toString();
275-
const auto error = unlock(p_notebookId, name);
276-
return error == VXCORE_OK || error == VXCORE_ERR_CANCELLED ? error : fail(error);
299+
return unlock(p_notebookId, name);
277300
}
278301

279302
struct Source {
@@ -326,7 +349,7 @@ VxCoreError NotebookExplorer2::prepareNotebookEncryption(const QString &p_notebo
326349
if (!source.unlocked) {
327350
const auto error = unlock(source.id, source.label);
328351
if (error != VXCORE_OK) {
329-
return error == VXCORE_ERR_CANCELLED ? error : fail(error);
352+
return error;
330353
}
331354
}
332355
} else {
@@ -375,7 +398,7 @@ VxCoreError NotebookExplorer2::prepareNotebookEncryption(const QString &p_notebo
375398
}
376399
p_progress.setLabelText(tr("Preparing the notebook key..."));
377400
p_setup = m_viewAreaController->prepareNoteEncryption(p_notebookId, sourceId, password);
378-
return p_setup.isValid() ? VXCORE_OK : fail(p_setup.m_error, p_setup.m_errorMessage);
401+
return p_setup.isValid() ? VXCORE_OK : fail(p_setup.m_error, p_setup.m_errorMessage, sourceId);
379402
}
380403

381404
NewNoteResult NotebookExplorer2::createEncryptedNote(const NewNoteInput &p_input) {

0 commit comments

Comments
 (0)