mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[price-quotes] Switch error handling to exceptions.
Allows for cleaner code with less state, less coupling of the GncQuotes class, and better transfer of error messages to client code. Also translates some error messages for presentation to users.
This commit is contained in:
parent
d307295076
commit
734fb6ce2a
@ -1785,18 +1785,19 @@ gnc_xfer_dialog_fetch (GtkButton *button, XferDialog *xferData)
|
|||||||
|
|
||||||
ENTER(" ");
|
ENTER(" ");
|
||||||
|
|
||||||
GncQuotes quotes;
|
try
|
||||||
if (quotes.cmd_result() != 0)
|
|
||||||
{
|
{
|
||||||
if (!quotes.error_msg().empty())
|
GncQuotes quotes;
|
||||||
PWARN ("%s", quotes.error_msg().c_str());
|
|
||||||
LEAVE("quote retrieval failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gnc_set_busy_cursor(nullptr, TRUE);
|
gnc_set_busy_cursor(nullptr, TRUE);
|
||||||
quotes.fetch(xferData->book);
|
quotes.fetch(xferData->book);
|
||||||
gnc_unset_busy_cursor(nullptr);
|
gnc_unset_busy_cursor(nullptr);
|
||||||
|
}
|
||||||
|
catch (const GncQuoteException& err)
|
||||||
|
{
|
||||||
|
gnc_unset_busy_cursor(nullptr);
|
||||||
|
PERR("Price retrieval failed: %s", err.what());
|
||||||
|
gnc_error_dialog(GTK_WINDOW(xferData->dialog), _("Price retrieval failed: %s"), err.what());
|
||||||
|
}
|
||||||
|
|
||||||
/*the results should be in the price db now, but don't crash if not. */
|
/*the results should be in the price db now, but don't crash if not. */
|
||||||
PriceReq pr;
|
PriceReq pr;
|
||||||
|
@ -559,18 +559,18 @@ gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data)
|
|||||||
auto pdb_dialog = static_cast<PricesDialog *> (data);
|
auto pdb_dialog = static_cast<PricesDialog *> (data);
|
||||||
|
|
||||||
ENTER(" ");
|
ENTER(" ");
|
||||||
|
try {
|
||||||
GncQuotes quotes;
|
GncQuotes quotes;
|
||||||
if (quotes.cmd_result() != 0)
|
|
||||||
{
|
|
||||||
if (!quotes.error_msg().empty())
|
|
||||||
PWARN ("%s", quotes.error_msg().c_str());
|
|
||||||
LEAVE("quote retrieval failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gnc_set_busy_cursor (NULL, TRUE);
|
gnc_set_busy_cursor (NULL, TRUE);
|
||||||
quotes.fetch (pdb_dialog->book);
|
quotes.fetch (pdb_dialog->book);
|
||||||
gnc_unset_busy_cursor (NULL);
|
gnc_unset_busy_cursor (NULL);
|
||||||
|
}
|
||||||
|
catch (const GncQuoteException& err)
|
||||||
|
{
|
||||||
|
gnc_unset_busy_cursor(nullptr);
|
||||||
|
PERR("Price retrieval failed: %s", err.what());
|
||||||
|
gnc_error_dialog(GTK_WINDOW(pdb_dialog), _("Price retrieval failed: %s"), err.what());
|
||||||
|
}
|
||||||
|
|
||||||
/* Without this, the summary bar on the accounts tab
|
/* Without this, the summary bar on the accounts tab
|
||||||
* won't reflect the new prices (bug #522095). */
|
* won't reflect the new prices (bug #522095). */
|
||||||
|
@ -303,9 +303,9 @@ int
|
|||||||
Gnucash::quotes_info (void)
|
Gnucash::quotes_info (void)
|
||||||
{
|
{
|
||||||
gnc_prefs_init ();
|
gnc_prefs_init ();
|
||||||
GncQuotes quotes;
|
try
|
||||||
if (quotes.cmd_result() == 0)
|
|
||||||
{
|
{
|
||||||
|
GncQuotes quotes;
|
||||||
std::cout << bl::format (bl::translate ("Found Finance::Quote version {1}.")) % quotes.version() << "\n";
|
std::cout << bl::format (bl::translate ("Found Finance::Quote version {1}.")) % quotes.version() << "\n";
|
||||||
std::cout << bl::translate ("Finance::Quote sources: ");
|
std::cout << bl::translate ("Finance::Quote sources: ");
|
||||||
for (auto source : quotes.sources())
|
for (auto source : quotes.sources())
|
||||||
@ -313,12 +313,9 @@ Gnucash::quotes_info (void)
|
|||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
catch (const GncQuoteException& err)
|
||||||
{
|
{
|
||||||
std::cerr << bl::translate ("Finance::Quote isn't "
|
std::cout << err.what() << std::endl;
|
||||||
"installed properly.") << "\n";
|
|
||||||
std::cerr << bl::translate ("Error message:") << "\n";
|
|
||||||
std::cerr << quotes.error_msg() << std::endl;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -341,32 +338,24 @@ Gnucash::add_quotes (const bo_str& uri)
|
|||||||
if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR)
|
if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR)
|
||||||
cleanup_and_exit_with_failure (session);
|
cleanup_and_exit_with_failure (session);
|
||||||
|
|
||||||
GncQuotes quotes;
|
try
|
||||||
if (quotes.cmd_result() == 0)
|
|
||||||
{
|
{
|
||||||
|
GncQuotes quotes;
|
||||||
std::cout << bl::format (bl::translate ("Found Finance::Quote version {1}.")) % quotes.version() << std::endl;
|
std::cout << bl::format (bl::translate ("Found Finance::Quote version {1}.")) % quotes.version() << std::endl;
|
||||||
auto quote_sources = quotes.sources_as_glist();
|
auto quote_sources = quotes.sources_as_glist();
|
||||||
gnc_quote_source_set_fq_installed (quotes.version().c_str(), quote_sources);
|
gnc_quote_source_set_fq_installed (quotes.version().c_str(), quote_sources);
|
||||||
g_list_free_full (quote_sources, g_free);
|
g_list_free_full (quote_sources, g_free);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cerr << bl::translate ("No quotes retrieved. Finance::Quote isn't "
|
|
||||||
"installed properly.") << "\n";
|
|
||||||
std::cerr << bl::translate ("Error message:") << std::endl;
|
|
||||||
std::cerr << quotes.error_msg() << std::endl;
|
|
||||||
}
|
|
||||||
quotes.fetch(qof_session_get_book(session));
|
quotes.fetch(qof_session_get_book(session));
|
||||||
|
}
|
||||||
|
catch (const GncQuoteException& err)
|
||||||
|
{
|
||||||
|
std::cerr << err.what() << std::endl;
|
||||||
|
}
|
||||||
qof_session_save(session, NULL);
|
qof_session_save(session, NULL);
|
||||||
if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR)
|
if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR)
|
||||||
cleanup_and_exit_with_failure (session);
|
cleanup_and_exit_with_failure (session);
|
||||||
|
|
||||||
qof_session_destroy(session);
|
qof_session_destroy(session);
|
||||||
|
|
||||||
if (quotes.cmd_result() != 0)
|
|
||||||
std::cerr << bl::format (bl::translate ("Failed to add quotes to {1}.")) % *uri << "\n";
|
|
||||||
|
|
||||||
qof_event_resume();
|
qof_event_resume();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -174,24 +174,24 @@ scm_run_gnucash (void *data, [[maybe_unused]] int argc, [[maybe_unused]] char **
|
|||||||
gnc_hook_add_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit, NULL, NULL);
|
gnc_hook_add_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit, NULL, NULL);
|
||||||
|
|
||||||
/* Install Price Quote Sources */
|
/* Install Price Quote Sources */
|
||||||
auto msg = bl::translate ("Checking Finance::Quote...").str(gnc_get_boost_locale());
|
|
||||||
|
|
||||||
GncQuotes quotes;
|
try
|
||||||
if (quotes.cmd_result() == 0)
|
|
||||||
{
|
{
|
||||||
|
auto msg = bl::translate ("Checking Finance::Quote...").str(gnc_get_boost_locale());
|
||||||
|
GncQuotes quotes;
|
||||||
msg = (bl::format (bl::translate("Found Finance::Quote version {1}.")) % quotes.version()).str(gnc_get_boost_locale());
|
msg = (bl::format (bl::translate("Found Finance::Quote version {1}.")) % quotes.version()).str(gnc_get_boost_locale());
|
||||||
auto quote_sources = quotes.sources_as_glist();
|
auto quote_sources = quotes.sources_as_glist();
|
||||||
gnc_quote_source_set_fq_installed (quotes.version().c_str(), quote_sources);
|
gnc_quote_source_set_fq_installed (quotes.version().c_str(), quote_sources);
|
||||||
g_list_free (quote_sources);
|
g_list_free (quote_sources);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg = bl::translate("Unable to load Finance::Quote.").str(gnc_get_boost_locale());
|
|
||||||
PINFO ("Attempt to load Finance::Quote returned this error message:\n");
|
|
||||||
PINFO ("%s", quotes.error_msg().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
gnc_update_splash_screen (msg.c_str(), GNC_SPLASH_PERCENTAGE_UNKNOWN);
|
gnc_update_splash_screen (msg.c_str(), GNC_SPLASH_PERCENTAGE_UNKNOWN);
|
||||||
|
}
|
||||||
|
catch (const GncQuoteException& err)
|
||||||
|
{
|
||||||
|
auto msg = bl::translate("Unable to load Finance::Quote.").str(gnc_get_boost_locale());
|
||||||
|
PINFO ("Attempt to load Finance::Quote returned this error message:\n");
|
||||||
|
PINFO ("%s", err.what());
|
||||||
|
gnc_update_splash_screen (msg.c_str(), GNC_SPLASH_PERCENTAGE_UNKNOWN);
|
||||||
|
}
|
||||||
|
|
||||||
gnc_hook_run(HOOK_STARTUP, NULL);
|
gnc_hook_run(HOOK_STARTUP, NULL);
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ set(app_utils_ALL_LIBRARIES
|
|||||||
gnc-engine
|
gnc-engine
|
||||||
${Boost_FILESYSTEM_LIBRARY}
|
${Boost_FILESYSTEM_LIBRARY}
|
||||||
${Boost_PROPERTY_TREE_LIBRARY}
|
${Boost_PROPERTY_TREE_LIBRARY}
|
||||||
|
${Boost_LOCALE_LIBRARY}
|
||||||
${GIO_LDFLAGS}
|
${GIO_LDFLAGS}
|
||||||
${LIBXML2_LDFLAGS}
|
${LIBXML2_LDFLAGS}
|
||||||
${LIBXSLT_LDFLAGS}
|
${LIBXSLT_LDFLAGS}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <stdexcept>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -34,6 +35,7 @@
|
|||||||
#include <boost/property_tree/json_parser.hpp>
|
#include <boost/property_tree/json_parser.hpp>
|
||||||
#include <boost/iostreams/device/array.hpp>
|
#include <boost/iostreams/device/array.hpp>
|
||||||
#include <boost/iostreams/stream_buffer.hpp>
|
#include <boost/iostreams/stream_buffer.hpp>
|
||||||
|
#include <boost/locale.hpp>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include "gnc-commodity.hpp"
|
#include "gnc-commodity.hpp"
|
||||||
@ -53,6 +55,7 @@ extern "C" {
|
|||||||
|
|
||||||
static const QofLogModule log_module = "gnc.price-quotes";
|
static const QofLogModule log_module = "gnc.price-quotes";
|
||||||
|
|
||||||
|
namespace bl = boost::locale;
|
||||||
namespace bp = boost::process;
|
namespace bp = boost::process;
|
||||||
namespace bfs = boost::filesystem;
|
namespace bfs = boost::filesystem;
|
||||||
namespace bpt = boost::property_tree;
|
namespace bpt = boost::property_tree;
|
||||||
@ -60,6 +63,11 @@ namespace bio = boost::iostreams;
|
|||||||
|
|
||||||
using QuoteResult = std::tuple<int, StrVec, StrVec>;
|
using QuoteResult = std::tuple<int, StrVec, StrVec>;
|
||||||
|
|
||||||
|
struct GncQuoteSourceError : public std::runtime_error
|
||||||
|
{
|
||||||
|
GncQuoteSourceError(const std::string& err) : std::runtime_error(err) {}
|
||||||
|
};
|
||||||
|
|
||||||
CommVec
|
CommVec
|
||||||
gnc_quotes_get_quotable_commodities(const gnc_commodity_table * table);
|
gnc_quotes_get_quotable_commodities(const gnc_commodity_table * table);
|
||||||
|
|
||||||
@ -85,8 +93,6 @@ public:
|
|||||||
void fetch (CommVec& commodities);
|
void fetch (CommVec& commodities);
|
||||||
void fetch (gnc_commodity *comm);
|
void fetch (gnc_commodity *comm);
|
||||||
|
|
||||||
int cmd_result() const noexcept { return m_cmd_result; }
|
|
||||||
const std::string& error_msg() noexcept { return m_error_msg; }
|
|
||||||
const std::string& version() noexcept { return m_version.empty() ? not_found : m_version; }
|
const std::string& version() noexcept { return m_version.empty() ? not_found : m_version; }
|
||||||
const QuoteSources& sources() noexcept { return m_sources; }
|
const QuoteSources& sources() noexcept { return m_sources; }
|
||||||
GList* sources_as_glist ();
|
GList* sources_as_glist ();
|
||||||
@ -101,8 +107,6 @@ private:
|
|||||||
CommVec m_comm_vec;
|
CommVec m_comm_vec;
|
||||||
std::string m_version;
|
std::string m_version;
|
||||||
QuoteSources m_sources;
|
QuoteSources m_sources;
|
||||||
int m_cmd_result;
|
|
||||||
std::string m_error_msg;
|
|
||||||
std::string m_fq_answer;
|
std::string m_fq_answer;
|
||||||
QofBook *m_book;
|
QofBook *m_book;
|
||||||
gnc_commodity *m_dflt_curr;
|
gnc_commodity *m_dflt_curr;
|
||||||
@ -138,21 +142,25 @@ m_version{}, m_sources{}
|
|||||||
auto [rv, sources, errors] = run_cmd(args, empty_string);
|
auto [rv, sources, errors] = run_cmd(args, empty_string);
|
||||||
if (rv)
|
if (rv)
|
||||||
{
|
{
|
||||||
PERR("Failed to initialize Finance::Quote %s", errors.front().c_str());
|
std::string err{bl::translate("Failed to initialize Finance::Quote: ")};
|
||||||
return;
|
for (auto err_line : errors)
|
||||||
|
err += err_line.empty() ? "" : err_line + "\n";
|
||||||
|
throw(GncQuoteSourceError(err));
|
||||||
}
|
}
|
||||||
if (!errors.empty())
|
if (!errors.empty())
|
||||||
{
|
{
|
||||||
for(const auto& err : errors)
|
std::string err{bl::translate("Finance::Quote check returned error ")};
|
||||||
PERR("Finance::Quote check returned error %s", err.empty() ? "" : err.c_str());
|
for(const auto& err_line : errors)
|
||||||
return;
|
err += err.empty() ? "" : err_line + "\n";
|
||||||
|
throw(GncQuoteSourceError(err));
|
||||||
}
|
}
|
||||||
static const boost::regex version_fmt{"[0-9]\\.[0-9][0-9]"};
|
static const boost::regex version_fmt{"[0-9]\\.[0-9][0-9]"};
|
||||||
auto version{sources.front()};
|
auto version{sources.front()};
|
||||||
if (version.empty() || !boost::regex_match(version, version_fmt))
|
if (version.empty() || !boost::regex_match(version, version_fmt))
|
||||||
{
|
{
|
||||||
PERR("Invalid Finance::Quote Version %s", version.empty() ? "" : version.c_str());
|
std::string err{bl::translate("Invalid Finance::Quote Version ")};
|
||||||
return;
|
err += version.empty() ? "" : version;
|
||||||
|
throw(GncQuoteSourceError(err));
|
||||||
}
|
}
|
||||||
m_ready = true;
|
m_ready = true;
|
||||||
sources.erase(sources.begin());
|
sources.erase(sources.begin());
|
||||||
@ -221,7 +229,7 @@ GncFQQuoteSource::run_cmd (const StrVec& args, const std::string& json_string) c
|
|||||||
|
|
||||||
/* GncQuotes implementation */
|
/* GncQuotes implementation */
|
||||||
GncQuotesImpl::GncQuotesImpl() : m_quotesource{new GncFQQuoteSource},
|
GncQuotesImpl::GncQuotesImpl() : m_quotesource{new GncFQQuoteSource},
|
||||||
m_version{}, m_sources{}, m_cmd_result{}, m_error_msg{}, m_book{qof_session_get_book(gnc_get_current_session())},
|
m_version{}, m_sources{}, m_book{qof_session_get_book(gnc_get_current_session())},
|
||||||
m_dflt_curr{gnc_default_currency()}
|
m_dflt_curr{gnc_default_currency()}
|
||||||
{
|
{
|
||||||
if (!m_quotesource->usable())
|
if (!m_quotesource->usable())
|
||||||
@ -230,7 +238,7 @@ m_dflt_curr{gnc_default_currency()}
|
|||||||
}
|
}
|
||||||
|
|
||||||
GncQuotesImpl::GncQuotesImpl(QofBook* book) : m_quotesource{new GncFQQuoteSource},
|
GncQuotesImpl::GncQuotesImpl(QofBook* book) : m_quotesource{new GncFQQuoteSource},
|
||||||
m_version{}, m_sources{}, m_cmd_result{}, m_error_msg{}, m_book{book},
|
m_version{}, m_sources{}, m_book{book},
|
||||||
m_dflt_curr{gnc_default_currency()}
|
m_dflt_curr{gnc_default_currency()}
|
||||||
{
|
{
|
||||||
if (!m_quotesource->usable())
|
if (!m_quotesource->usable())
|
||||||
@ -240,8 +248,7 @@ m_dflt_curr{gnc_default_currency()}
|
|||||||
|
|
||||||
GncQuotesImpl::GncQuotesImpl(QofBook* book, std::unique_ptr<GncQuoteSource> quote_source) :
|
GncQuotesImpl::GncQuotesImpl(QofBook* book, std::unique_ptr<GncQuoteSource> quote_source) :
|
||||||
m_quotesource{std::move(quote_source)},
|
m_quotesource{std::move(quote_source)},
|
||||||
m_version{}, m_sources{}, m_cmd_result{}, m_error_msg{}, m_book{book},
|
m_version{}, m_sources{}, m_book{book}, m_dflt_curr{gnc_default_currency()}
|
||||||
m_dflt_curr{gnc_default_currency()}
|
|
||||||
{
|
{
|
||||||
if (!m_quotesource->usable())
|
if (!m_quotesource->usable())
|
||||||
return;
|
return;
|
||||||
@ -262,12 +269,7 @@ void
|
|||||||
GncQuotesImpl::fetch (QofBook *book)
|
GncQuotesImpl::fetch (QofBook *book)
|
||||||
{
|
{
|
||||||
if (!book)
|
if (!book)
|
||||||
{
|
throw (GncQuoteException(bl::translate("GncQuotes::Fetch called with no book.")));
|
||||||
m_cmd_result = 1;
|
|
||||||
m_error_msg = _("No book set");
|
|
||||||
m_error_msg += "\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto commodities = gnc_quotes_get_quotable_commodities (
|
auto commodities = gnc_quotes_get_quotable_commodities (
|
||||||
gnc_commodity_table_get_table (book));
|
gnc_commodity_table_get_table (book));
|
||||||
fetch (commodities);
|
fetch (commodities);
|
||||||
@ -290,7 +292,6 @@ GncQuotesImpl::fetch (CommVec& commodities)
|
|||||||
m_book = qof_instance_get_book (m_comm_vec[0]);
|
m_book = qof_instance_get_book (m_comm_vec[0]);
|
||||||
|
|
||||||
query_fq ();
|
query_fq ();
|
||||||
if (m_cmd_result == 0)
|
|
||||||
parse_quotes ();
|
parse_quotes ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,14 +337,19 @@ GncQuotesImpl::query_fq (void)
|
|||||||
auto json_str{comm_vec_to_json_string()};
|
auto json_str{comm_vec_to_json_string()};
|
||||||
auto [rv, quotes, errors] = m_quotesource->get_quotes(json_str);
|
auto [rv, quotes, errors] = m_quotesource->get_quotes(json_str);
|
||||||
m_fq_answer.clear();
|
m_fq_answer.clear();
|
||||||
m_cmd_result = rv;
|
|
||||||
if (rv == 0)
|
if (rv == 0)
|
||||||
|
{
|
||||||
for (auto line : quotes)
|
for (auto line : quotes)
|
||||||
m_fq_answer.append(line + "\n");
|
m_fq_answer.append(line + "\n");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
std::string err_str;
|
||||||
for (auto line: errors)
|
for (auto line: errors)
|
||||||
m_error_msg.append(line + "\n");
|
err_str.append(line + "\n");
|
||||||
|
throw(GncQuoteException(err_str));
|
||||||
|
}
|
||||||
// for (auto line : quotes)
|
// for (auto line : quotes)
|
||||||
// PINFO("Output line retrieved from wrapper:\n%s", line.c_str());
|
// PINFO("Output line retrieved from wrapper:\n%s", line.c_str());
|
||||||
//
|
//
|
||||||
@ -546,24 +552,35 @@ GncQuotesImpl::parse_quotes (void)
|
|||||||
{
|
{
|
||||||
bpt::ptree pt;
|
bpt::ptree pt;
|
||||||
std::istringstream ss {m_fq_answer};
|
std::istringstream ss {m_fq_answer};
|
||||||
|
const char* what = nullptr;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bpt::read_json (ss, pt);
|
bpt::read_json (ss, pt);
|
||||||
}
|
}
|
||||||
catch (bpt::json_parser_error &e) {
|
catch (bpt::json_parser_error &e) {
|
||||||
m_cmd_result = -1;
|
what = e.what();
|
||||||
m_error_msg = m_error_msg +
|
}
|
||||||
_("Failed to parse result returned by Finance::Quote.") + "\n" +
|
catch (const std::runtime_error& e)
|
||||||
_("Error message:") + "\n" +
|
{
|
||||||
e.what() + "\n";
|
what = e.what();
|
||||||
return;
|
}
|
||||||
|
catch (const std::logic_error& e)
|
||||||
|
{
|
||||||
|
what = e.what();
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
m_cmd_result = -1;
|
std::string error_msg{_("Failed to parse result returned by Finance::Quote.")};
|
||||||
m_error_msg = m_error_msg +
|
throw(GncQuoteException(error_msg));
|
||||||
_("Failed to parse result returned by Finance::Quote.") + "\n";
|
}
|
||||||
return;
|
if (what)
|
||||||
|
{
|
||||||
|
std::string error_msg{_("Failed to parse result returned by Finance::Quote.")};
|
||||||
|
error_msg += "\n";
|
||||||
|
error_msg += _("Error message:");
|
||||||
|
error_msg += "\n";
|
||||||
|
error_msg += what;
|
||||||
|
throw(GncQuoteException(error_msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pricedb{gnc_pricedb_get_db(m_book)};
|
auto pricedb{gnc_pricedb_get_db(m_book)};
|
||||||
@ -671,9 +688,17 @@ gnc_quotes_get_quotable_commodities (const gnc_commodity_table * table)
|
|||||||
/* Public interface functions */
|
/* Public interface functions */
|
||||||
// Constructor - checks for presence of Finance::Quote and import version and quote sources
|
// Constructor - checks for presence of Finance::Quote and import version and quote sources
|
||||||
GncQuotes::GncQuotes ()
|
GncQuotes::GncQuotes ()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
m_impl = std::make_unique<GncQuotesImpl>();
|
m_impl = std::make_unique<GncQuotesImpl>();
|
||||||
}
|
}
|
||||||
|
catch (const GncQuoteSourceError& err)
|
||||||
|
{
|
||||||
|
throw(GncQuoteException(err.what()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GncQuotes::fetch (QofBook *book)
|
GncQuotes::fetch (QofBook *book)
|
||||||
@ -691,16 +716,6 @@ void GncQuotes::fetch (gnc_commodity *comm)
|
|||||||
m_impl->fetch (comm);
|
m_impl->fetch (comm);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int GncQuotes::cmd_result() noexcept
|
|
||||||
{
|
|
||||||
return m_impl->cmd_result ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& GncQuotes::error_msg() noexcept
|
|
||||||
{
|
|
||||||
return m_impl->error_msg ();
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& GncQuotes::version() noexcept
|
const std::string& GncQuotes::version() noexcept
|
||||||
{
|
{
|
||||||
return m_impl->version ();
|
return m_impl->version ();
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <gnc-commodity.hpp> // For CommVec alias
|
#include <gnc-commodity.hpp> // For CommVec alias
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <qofbook.h>
|
#include <qofbook.h>
|
||||||
@ -36,6 +37,11 @@ using StrVec = std::vector <std::string>;
|
|||||||
using QuoteSources = StrVec;
|
using QuoteSources = StrVec;
|
||||||
using CmdOutput = std::pair <StrVec, StrVec>;
|
using CmdOutput = std::pair <StrVec, StrVec>;
|
||||||
|
|
||||||
|
struct GncQuoteException : public std::runtime_error
|
||||||
|
{
|
||||||
|
GncQuoteException(const std::string& msg) : std::runtime_error(msg) {}
|
||||||
|
};
|
||||||
|
|
||||||
const std::string not_found = std::string ("Not Found");
|
const std::string not_found = std::string ("Not Found");
|
||||||
|
|
||||||
class GncQuotesImpl;
|
class GncQuotesImpl;
|
||||||
@ -54,8 +60,6 @@ public:
|
|||||||
// Fetch quote for the commodity if it has a quote source set
|
// Fetch quote for the commodity if it has a quote source set
|
||||||
void fetch (gnc_commodity *comm);
|
void fetch (gnc_commodity *comm);
|
||||||
|
|
||||||
const int cmd_result() noexcept;
|
|
||||||
const std::string& error_msg() noexcept;
|
|
||||||
const std::string& version() noexcept;
|
const std::string& version() noexcept;
|
||||||
const QuoteSources& sources() noexcept;
|
const QuoteSources& sources() noexcept;
|
||||||
GList* sources_as_glist ();
|
GList* sources_as_glist ();
|
||||||
|
@ -44,6 +44,7 @@ set(test_gnc_quotes_LIBS
|
|||||||
gnc-engine
|
gnc-engine
|
||||||
gtest
|
gtest
|
||||||
${Boost_FILESYSTEM_LIBRARY}
|
${Boost_FILESYSTEM_LIBRARY}
|
||||||
|
${Boost_LOCALE_LIBRARY}
|
||||||
${Boost_PROPERTY_TREE_LIBRARY}
|
${Boost_PROPERTY_TREE_LIBRARY}
|
||||||
${Boost_SYSTEM_LIBRARY}
|
${Boost_SYSTEM_LIBRARY}
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user