r18596 - gnucash/trunk/src/report/report-system - Bug #606728: Catch errors when opening saved-reports-2.4 for write.

Andreas Köhler andi5 at code.gnucash.org
Sun Jan 31 16:12:21 EST 2010


Author: andi5
Date: 2010-01-31 16:12:21 -0500 (Sun, 31 Jan 2010)
New Revision: 18596
Trac: http://svn.gnucash.org/trac/changeset/18596

Modified:
   gnucash/trunk/src/report/report-system/report.scm
Log:
Bug #606728: Catch errors when opening saved-reports-2.4 for write.

Modified: gnucash/trunk/src/report/report-system/report.scm
===================================================================
--- gnucash/trunk/src/report/report-system/report.scm	2010-01-31 21:12:18 UTC (rev 18595)
+++ gnucash/trunk/src/report/report-system/report.scm	2010-01-31 21:12:21 UTC (rev 18596)
@@ -567,35 +567,46 @@
 (define gnc:current-saved-reports
   (gnc-build-dotgnucash-path "saved-reports-2.4"))
 
+(define (gnc:open-saved-reports mode)
+  (let ((conf-file-name gnc:current-saved-reports))
+    (catch #t
+           (lambda () (open-file conf-file-name mode))
+           (lambda (key . args)
+             (gnc-error-dialog
+              '()
+              (string-append (_ "Could not open the file: ") conf-file-name (_ ". The error is: ") (symbol->string key) " - " (car (caddr args)) "."))
+             #f))))
+
 (define (gnc:report-save-to-savefile report)
-  (let* ((conf-file-name gnc:current-saved-reports)
-         (saved-form (gnc:report-generate-saved-forms report))
+  (let* ((saved-form (gnc:report-generate-saved-forms report))
          ;; Immediate evaluate the saved form to both load it into the
          ;; runtime, but also so we can check if it's "allowed" to actually
          ;; be written to the saved reports file by inspecting the result.
          ;; #Bug#342206.
          (save-result (eval-string saved-form)))
     (if (record? save-result)
-        (let ((report-port (open-file conf-file-name "a")))
-          (display saved-form report-port)
-          (close report-port)
-	      (let ((report-name (gnc:report-name report)))
-		(gnc-info-dialog
-		 '()
-		 (sprintf 
-		  #f (_ "Your report \"%s\" has been saved into the configuration file \"%s\".")
-		  (if (and report-name (not (string-null? report-name)))
-		      (gnc:gettext report-name)
-		      (gnc:gettext "Untitled"))
-		  conf-file-name)))
-	  ))))
+        (let ((report-port (gnc:open-saved-reports "a")))
+          (if report-port
+              (begin
+                (display saved-form report-port)
+                (close report-port)
+                (let ((report-name (gnc:report-name report)))
+                  (gnc-info-dialog
+                   '()
+                   (sprintf
+                    #f (_ "Your report \"%s\" has been saved into the configuration file \"%s\".")
+                    (if (and report-name (not (string-null? report-name)))
+                        (gnc:gettext report-name)
+                        (gnc:gettext "Untitled"))
+                    gnc:current-saved-reports)))
+                ))))))
 
 (define (gnc:report-template-save-to-savefile report-template)
-  (let* ((conf-file-name gnc:current-saved-reports)
-	(saved-form (gnc:report-template-generate-saved-forms report-template))
-	(report-port (open-file conf-file-name "a")))
-    (display saved-form report-port)
-    (close report-port)))
+  (let* ((report-port (gnc:open-saved-reports "a")))
+    (if report-port
+        (let ((saved-form (gnc:report-template-generate-saved-forms report-template)))
+          (display saved-form report-port)
+          (close report-port)))))
 
 ;; save all custom reports, moving the old version of the
 ;; saved-reports file aside as a backup



More information about the gnucash-changes mailing list