gnucash stable: [reports] more robust error handling if target report doesn't exist

Christopher Lam clam at code.gnucash.org
Sat Jun 7 08:29:30 EDT 2025


Updated	 via  https://github.com/Gnucash/gnucash/commit/c0a38d34 (commit)
	from  https://github.com/Gnucash/gnucash/commit/2fd89a27 (commit)



commit c0a38d34793e6f5309ebed7254633be19ca74fc9
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jun 7 17:59:40 2025 +0800

    [reports] more robust error handling if target report doesn't exist
    
    addendum last commit

diff --git a/gnucash/report/gnc-report.cpp b/gnucash/report/gnc-report.cpp
index 0a3974d3a7..32f94a6e1a 100644
--- a/gnucash/report/gnc-report.cpp
+++ b/gnucash/report/gnc-report.cpp
@@ -273,7 +273,9 @@ gnc_report_id_string_to_report_id (const char *id_string)
     if (end_ptr == anchor_str || *end_ptr != '\0') return -1;
 
     const SCM get_linked = scm_c_eval_string ("gnc:report-get-linked-report");
-    return scm_to_uint (scm_call_2 (get_linked, scm_from_uint (rpt_id), scm_from_uint (anchor_id)));
+
+    auto id = scm_call_2 (get_linked, scm_from_uint (rpt_id), scm_from_uint (anchor_id));
+    return scm_is_number (id) ? scm_to_int (id) : -1;
 }
 
 gboolean
diff --git a/gnucash/report/html-utilities.scm b/gnucash/report/html-utilities.scm
index 847da82abf..579dfd2e85 100644
--- a/gnucash/report/html-utilities.scm
+++ b/gnucash/report/html-utilities.scm
@@ -176,13 +176,13 @@
     ((reportname src-options optionlist)
      (let* ((options (gnc:make-report-options reportname))
             (db (gnc:optiondb options)))
-       (gnc:options-copy-values src-options options)
-       (for-each
-        (lambda (l)
-          (gnc-set-option db (car l) (cadr l) (caddr l)))
-        optionlist)
-       (gnc:make-report reportname options)))
-    (_ (gnc:error "invalid id " id))))
+       (cond
+        (options
+         (gnc:options-copy-values src-options options)
+         (for-each (lambda (l) (apply gnc-set-option db l)) optionlist)
+         (gnc:make-report reportname options))
+        (else (gnc:error "cannot find temport template " reportname) #f))))
+    (_ (gnc:error "invalid src-id " src-id " id " id) #f)))
 
 ;; returns the account name as html-text and anchor to the register.
 (define (gnc:html-account-anchor acct)



Summary of changes:
 gnucash/report/gnc-report.cpp     |  4 +++-
 gnucash/report/html-utilities.scm | 14 +++++++-------
 2 files changed, 10 insertions(+), 8 deletions(-)



More information about the gnucash-changes mailing list