On Tue, Mar 12, 2019 at 09:02:22AM +0100, Jürgen Spitzmüller wrote:
> Am Montag, den 11.03.2019, 18:59 +0100 schrieb Jürgen Womser-Schütz:
> > Hello Jürgen,
> > 
> > I think it is now much better than I could do it without your help. 

Thanks to the Jürgens for your work on this. On master branch, if I
export a file on the command-line with a child document that is not
found, I no longer get an error and the command exits "successfully"
(i.e., 0 exit code). It shows a warning in the terminal but it is easy
to miss it.

I attach a patch that amends c41df5b671e by converting the warning to an
error. Any objection? If preferred, we could show both the warning and
the error, but it seems reasonable to show just one message of the
problem.

I also attach an example .lyx file in case someone wants to experiment.
I intentionally do not attach the child .lyx file.

Scott
From 485e80aa4bb1dc1f1036a460cab5f3e11d69deff Mon Sep 17 00:00:00 2001
From: Scott Kostyshak <skost...@lyx.org>
Date: Fri, 16 Apr 2021 11:55:43 -0400
Subject: [PATCH] If file not found, give error instead of warn

c41df5b671e introduced a "warn and return" if an included file does
not exist. On the command line, an export now returns with a 0 exit
code in this case and thus a missing child can go undetected if
relying on command-line export.

Before c41df5b671e, the code would in some cases at least reach a
separate error, "Could not load included file"; however, the return
caused this error to not be reached.
---
 src/insets/InsetInclude.cpp | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index aeae2fb17d..907ead0d5f 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -548,15 +548,18 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
 			true);
 		return;
 	}
-	// Warn if file doesn't exist
+
+	// Give error if file doesn't exist. Without this error, an error is
+	// triggered in some cases by our check of the return value of
+	// loadIfNeeded() below, but not others so we give an error now to be
+	// sure.
 	if (!includedFileExist()) {
-		frontend::Alert::warning(_("Included file not found"),
-			bformat(_("The included file\n"
-				  "'%1$s'\n"
-				  "has not been found. LyX will ignore the inclusion."),
-				from_utf8(incfile)),
-			true);
-		 return;
+		docstring text = bformat(_("Included file not found. "
+			"File\n`%1$s'\n"
+			"has not been found."),
+				from_utf8(incfile));
+		throw ExceptionMessage(ErrorException, _("Error: "),
+					   text);
 	}
 
 	FileName const included_file = includedFileName(buffer(), params());
-- 
2.20.1

Attachment: example.lyx
Description: application/lyx

Attachment: signature.asc
Description: PGP signature

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to