commit e7171c951070b3e7cc66e645e59a1b31de20e67a
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Wed Feb 12 13:24:26 2025 +0100

    Improve error message with corrupted file if this underwent lyx2lyx (#13153)
---
 src/Buffer.cpp | 23 +++++++++++++++++------
 src/Buffer.h   |  3 ++-
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index e86f4af227..d397c0ace5 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -1215,7 +1215,8 @@ bool Buffer::readString(string const & s)
 }
 
 
-Buffer::ReadStatus Buffer::readFile(FileName const & fn)
+Buffer::ReadStatus Buffer::readFile(FileName const & fn,
+                                   string const ofn)
 {
        Lexer lex;
        if (!lex.setFile(fn)) {
@@ -1235,7 +1236,7 @@ Buffer::ReadStatus Buffer::readFile(FileName const & fn)
                ReadStatus ret_clf = convertLyXFormat(fn, tmpFile, file_format);
                if (ret_clf != ReadSuccess)
                        return ret_clf;
-               ret_clf = readFile(tmpFile);
+               ret_clf = readFile(tmpFile, fn.absFileName());
                if (ret_clf == ReadSuccess) {
                        d->file_format = file_format;
                        d->need_format_backup = true;
@@ -1248,10 +1249,20 @@ Buffer::ReadStatus Buffer::readFile(FileName const & fn)
        lyxvc().file_found_hook(d->filename);
 
        if (readDocument(lex)) {
-               Alert::error(_("Document format failure"),
-                       bformat(_("%1$s ended unexpectedly, which means"
-                               " that it is probably corrupted."),
-                                       from_utf8(fn.absFileName())));
+               // if we have a lyx2lyx-converted document, tell user both
+               // the original file name and the converted's as the corruption
+               // might be in the latter only or in both (#13153).
+               docstring const msg = ofn.empty()
+                               ? bformat(_("%1$s ended unexpectedly, which 
means"
+                                           " that it is probably corrupted."),
+                                           from_utf8(fn.absFileName()))
+                               : bformat(_("The converted version of %1$s to 
current LyX format"
+                                           " ended unexpectedly, which means"
+                                           " that it is probably corrupted.\n"
+                                           "You can find the converted file at 
%2$s"
+                                           " while LyX is running."),
+                                         from_utf8(ofn), 
from_utf8(fn.absFileName()));
+               Alert::error(_("Document format failure"), msg);
                return ReadDocumentFailure;
        }
 
diff --git a/src/Buffer.h b/src/Buffer.h
index fa240a4cbf..8c19d3d18a 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -243,7 +243,8 @@ private:
        /// save checksum of the given file.
        void saveCheckSum() const;
        /// read a new file
-       ReadStatus readFile(support::FileName const & fn);
+       ReadStatus readFile(support::FileName const & fn,
+                           std::string ofn = std::string());
        /// Reads a file without header.
        /// \param par if != 0 insert the file.
        /// \return \c true if file is not completely read.
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to