gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Sat Jan 2 17:36:39 EST 2021
Updated via https://github.com/Gnucash/gnucash/commit/1e7433da (commit)
via https://github.com/Gnucash/gnucash/commit/ca606e76 (commit)
via https://github.com/Gnucash/gnucash/commit/15ecf114 (commit)
via https://github.com/Gnucash/gnucash/commit/955043b8 (commit)
via https://github.com/Gnucash/gnucash/commit/a169ee70 (commit)
via https://github.com/Gnucash/gnucash/commit/1151b2c4 (commit)
from https://github.com/Gnucash/gnucash/commit/89da0f10 (commit)
commit 1e7433daf3307fb3e6ff6d479aacb22d42941fda
Merge: 89da0f10b ca606e769
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Jan 3 06:31:39 2021 +0800
Merge branch 'maint-augment-run-report' into maint #857
commit ca606e7694563b273292e1c23999f77544a474ae
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Jan 2 23:28:39 2021 +0800
[c-interface.scm] deprecate gnc:last-captured-error
diff --git a/libgnucash/app-utils/c-interface.scm b/libgnucash/app-utils/c-interface.scm
index c4a414803..0468fe501 100644
--- a/libgnucash/app-utils/c-interface.scm
+++ b/libgnucash/app-utils/c-interface.scm
@@ -78,11 +78,12 @@
((result #f) result)
((_ captured-error)
(display captured-error (current-error-port))
+ ;; the next line will be removed in 5.x - deprecated
(set! gnc:last-captured-error (gnc:html-string-sanitize captured-error))
(when (defined? 'gnc:warn) (gnc:warn captured-error))
#f)))
-(define gnc:last-captured-error "")
+(define gnc:last-captured-error "") ;deprecate - remove in 5.x
;; This database can be used to store and retrieve translatable
;; strings. Strings that are returned by the lookup function are
commit 15ecf114c64e65f2b102946e18665a53e1a7e70a
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Jan 2 21:45:45 2021 +0800
[gnucash-commands.cpp] display report errors to stderr
diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp
index 4b1bd8448..488a93cb9 100644
--- a/gnucash/gnucash-commands.cpp
+++ b/gnucash/gnucash-commands.cpp
@@ -260,9 +260,9 @@ return a document object with export-string or export-error.") << std::endl;
if (scm_is_false (id))
scm_cleanup_and_exit_with_failure (nullptr);
- char* html;
- gnc_run_report (scm_to_int(id), &html);
- if (html && *html)
+ char *html, *errmsg;
+
+ if (gnc_run_report_with_error_handling (scm_to_int(id), &html, &errmsg))
{
if (!args->output_file.empty())
{
@@ -273,6 +273,10 @@ return a document object with export-string or export-error.") << std::endl;
std::cout << html << std::endl;
}
}
+ else
+ {
+ std::cerr << errmsg << std::endl;
+ }
}
qof_session_destroy (session);
commit 955043b8c913a71b4c026d178c81c1404f4fe0e2
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Jan 2 21:23:15 2021 +0800
[gnc-plugin-report-system.c] use gnc_run_report_id_string_with_error_handling
don't use gnc_run_report_id_string
diff --git a/gnucash/gnome/gnc-plugin-report-system.c b/gnucash/gnome/gnc-plugin-report-system.c
index f261df7a0..3016f9937 100644
--- a/gnucash/gnome/gnc-plugin-report-system.c
+++ b/gnucash/gnome/gnc-plugin-report-system.c
@@ -137,14 +137,12 @@ static gboolean
gnc_report_system_report_stream_cb (const char *location, char ** data, int *len)
{
gboolean ok;
+ gchar *captured_str;
- ok = gnc_run_report_id_string (location, data);
+ ok = gnc_run_report_id_string_with_error_handling (location, data, &captured_str);
if (!ok)
{
- SCM captured = scm_c_eval_string ("gnc:last-captured-error");
- gchar *captured_str = gnc_scm_to_utf8_string(captured);
-
*data = g_strdup_printf ("<html><body><h3>%s</h3>"
"<p>%s</p><pre>%s</pre></body></html>",
_("Report error"),
commit a169ee70c2dfebeaa0565099c68e6531e7c0f9f3
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Jan 2 21:22:10 2021 +0800
[gnc-report.c] expose gnc_run_report_id_string_with_error_handling
similar to gnc_run_report_id_string but also receives and populates
**errmsg if the report crashes
diff --git a/gnucash/report/gnc-report.c b/gnucash/report/gnc-report.c
index 3981740df..c8ed10c15 100644
--- a/gnucash/report/gnc-report.c
+++ b/gnucash/report/gnc-report.c
@@ -206,6 +206,34 @@ gnc_reports_get_global(void)
return reports;
}
+gboolean
+gnc_run_report_with_error_handling (gint report_id, gchar ** data, gchar **errmsg)
+{
+ SCM report, res, html, captured_error;
+
+ report = gnc_report_find (report_id);
+ g_return_val_if_fail (data, FALSE);
+ g_return_val_if_fail (errmsg, FALSE);
+ g_return_val_if_fail (!scm_is_false (report), FALSE);
+
+ res = scm_call_1 (scm_c_eval_string ("gnc:render-report"), report);
+ html = scm_car (res);
+ captured_error = scm_cadr (res);
+
+ if (!scm_is_false (html))
+ {
+ *data = gnc_scm_to_utf8_string (html);
+ *errmsg = NULL;
+ return TRUE;
+ }
+ else
+ {
+ *errmsg = gnc_scm_to_utf8_string (captured_error);
+ *data = NULL;
+ return FALSE;
+ }
+}
+
static void
error_handler(const char *str)
{
@@ -218,6 +246,8 @@ gnc_run_report (gint report_id, char ** data)
SCM scm_text;
gchar *str;
+ PWARN ("gnc_run_report is deprecated. use gnc_run_report_with_error_handling instead.");
+
g_return_val_if_fail (data != NULL, FALSE);
*data = NULL;
@@ -238,6 +268,8 @@ gnc_run_report_id_string (const char * id_string, char **data)
{
gint report_id;
+ PWARN ("gnc_run_report_id_string is deprecated. use gnc_run_report_id_string_with_error_handling instead.");
+
g_return_val_if_fail (id_string != NULL, FALSE);
g_return_val_if_fail (data != NULL, FALSE);
*data = NULL;
@@ -262,6 +294,25 @@ gnc_report_name( SCM report )
return gnc_scm_call_1_to_string(get_name, report);
}
+gboolean
+gnc_run_report_id_string_with_error_handling (const char * id_string, char **data,
+ gchar **errmsg)
+{
+ gint report_id;
+
+ g_return_val_if_fail (id_string, FALSE);
+ g_return_val_if_fail (data, FALSE);
+ *data = NULL;
+
+ if (strncmp ("id=", id_string, 3) != 0)
+ return FALSE;
+
+ if (sscanf (id_string + 3, "%d", &report_id) != 1)
+ return FALSE;
+
+ return gnc_run_report_with_error_handling (report_id, data, errmsg);
+}
+
gchar*
gnc_get_default_report_font_family(void)
{
diff --git a/gnucash/report/gnc-report.h b/gnucash/report/gnc-report.h
index 4bf597288..3641528c3 100644
--- a/gnucash/report/gnc-report.h
+++ b/gnucash/report/gnc-report.h
@@ -39,7 +39,13 @@ void gnc_report_init (void);
gboolean gnc_run_report (gint report_id, char ** data);
+gboolean gnc_run_report_with_error_handling (gint report_id,
+ gchar **data,
+ gchar **errmsg);
gboolean gnc_run_report_id_string (const char * id_string, char **data);
+gboolean gnc_run_report_id_string_with_error_handling (const char * id_string,
+ char **data,
+ gchar **errmsg);
/**
* @param report The SCM version of the report.
commit 1151b2c402825e7ca68038c19ffcd2775ed5c55f
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Jan 2 21:15:48 2021 +0800
[report-core.scm] create and expose gnc:render-report
similar to gnc:report-run but *always* returns a 2-element list
containing data OR captured_error
diff --git a/gnucash/report/report-core.scm b/gnucash/report/report-core.scm
index 3b56f04e6..931f873a3 100644
--- a/gnucash/report/report-core.scm
+++ b/gnucash/report/report-core.scm
@@ -76,6 +76,7 @@
(export gnc:report-needs-save?)
(export gnc:report-options)
(export gnc:report-render-html)
+(export gnc:render-report)
(export gnc:report-run)
(export gnc:report-serialize)
(export gnc:report-set-ctext!)
@@ -763,9 +764,17 @@ not found.")))
(gnc:report-set-dirty?! report #f) ;; mark it clean
html)))))
+;; render report. will return a 2-element list: either (list html #f)
+;; where html is the report html string, or (list #f captured-error)
+;; where captured-error is the error string.
+(define (gnc:render-report report)
+ (define (get-report) (gnc:report-render-html report #t))
+ (gnc:apply-with-error-handling get-report '()))
+
;; looks up the report by id and renders it with gnc:report-render-html
;; marks the cursor busy during rendering; returns the html
(define (gnc:report-run id)
+ (issue-deprecation-warning "gnc:report-run is deprecated. use gnc:render-report instead.")
(let ((report (gnc-report-find id))
(html #f))
(gnc-set-busy-cursor '() #t)
Summary of changes:
gnucash/gnome/gnc-plugin-report-system.c | 6 ++--
gnucash/gnucash-commands.cpp | 10 +++++--
gnucash/report/gnc-report.c | 51 ++++++++++++++++++++++++++++++++
gnucash/report/gnc-report.h | 6 ++++
gnucash/report/report-core.scm | 9 ++++++
libgnucash/app-utils/c-interface.scm | 3 +-
6 files changed, 77 insertions(+), 8 deletions(-)
More information about the gnucash-changes
mailing list