[gnucash-commands] handle invalid renderer return

- renderer doesn't return an html-document object
- or, the html-document has no export-string nor export-error
This commit is contained in:
Christopher Lam 2020-08-16 08:25:50 +08:00
parent 6d217a7bcf
commit 21925c18be

View File

@ -193,7 +193,6 @@ scm_run_report (void *data,
auto type = !args->export_type.empty() ?
scm_from_locale_string (args->export_type.c_str()) : SCM_BOOL_F;
/* dry-run? is #t: try report, check validity of options */
if (scm_is_false (scm_call_2 (check_report_cmd, report, type)))
scm_cleanup_and_exit_with_failure (nullptr);
@ -216,8 +215,17 @@ scm_run_report (void *data,
if (!args->export_type.empty())
{
SCM retval = scm_call_2 (run_export_cmd, report, type);
SCM query_result = scm_c_eval_string ("gnc:html-document?");
SCM get_export_string = scm_c_eval_string ("gnc:html-document-export-string");
SCM get_export_error = scm_c_eval_string ("gnc:html-document-export-error");
if (scm_is_false (scm_call_1 (query_result, retval)))
{
std::cerr << _("This report must be upgraded to \
return a document object with export-string or export-error.") << std::endl;
scm_cleanup_and_exit_with_failure (nullptr);
}
SCM export_string = scm_call_1 (get_export_string, retval);
SCM export_error = scm_call_1 (get_export_error, retval);
@ -236,7 +244,13 @@ scm_run_report (void *data,
else if (scm_is_string (export_error))
{
auto err = scm_to_utf8_string (export_error);
std::cout << err << std::endl;
std::cerr << err << std::endl;
scm_cleanup_and_exit_with_failure (nullptr);
}
else
{
std::cerr << _("This report must be upgraded to \
return a document object with export-string or export-error.") << std::endl;
scm_cleanup_and_exit_with_failure (nullptr);
}
}