[LON-CAPA-cvs] cvs: loncom /xml lontex.pm

raeburn raeburn at source.lon-capa.org
Wed Feb 19 19:41:11 EST 2025


raeburn		Thu Feb 20 00:41:11 2025 EDT

  Modified files:              
    /loncom/xml	lontex.pm 
  Log:
  - Check if .tex file exists before attempting to open it, and display error
    page if it doesn't exist. 
  
  
Index: loncom/xml/lontex.pm
diff -u loncom/xml/lontex.pm:1.14 loncom/xml/lontex.pm:1.15
--- loncom/xml/lontex.pm:1.14	Fri Dec 22 13:38:01 2023
+++ loncom/xml/lontex.pm	Thu Feb 20 00:41:11 2025
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # TeX Content Handler
 #
-# $Id: lontex.pm,v 1.14 2023/12/22 13:38:01 raeburn Exp $
+# $Id: lontex.pm,v 1.15 2025/02/20 00:41:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -46,12 +46,14 @@
 use Apache::lontexconvert;
 use Apache::Constants qw(:common);
 use Apache::lonnet;
+use Apache::loncommon;
+use Apache::lonmsg;
+use Apache::lonlocal;
 use tth;
 
 # ================================================================ Main Handler
 
 sub footer {
-    my ($errorstring) = @_;
     my $xmlstring='';
     if ($env{'request.state'} eq 'construct') {
 	$xmlstring.='<address>'.
@@ -84,8 +86,21 @@
 # ------------------------------------------------------------------- Read file
 
   {
-    my $fh=Apache::File->new($r->filename);
-    @texcontents=<$fh>;
+      if (-e $r->filename) {
+          my $fh=Apache::File->new($r->filename);
+          @texcontents=<$fh>;
+          close($fh);
+      } else {
+            my $filename=(split('/',$r->filename))[-1];
+            my $error =
+                '<p class="LC_error">'
+               .&mt('Unable to find [_1]',
+                           '<span class="LC_filename">'.$filename.'</span>')
+                ."</p>";
+            &Apache::loncommon::simple_error_page($r,'Not available',
+                                                  $error,{'no_auto_mt_msg' => 1});
+            return OK;
+      }
   }
 
   $texstring=join("\n", at texcontents);




More information about the LON-CAPA-cvs mailing list