From 500a65a81d03f86bf7fa250ebc4cb87dc0e489a2 Mon Sep 17 00:00:00 2001 From: Andreas Buchen Date: Fri, 1 Mar 2024 08:28:28 +0100 Subject: [PATCH] Abbreviate error message when updating historical prices Reduce the pollution of stack trace in the log for common error messages that occur during the update of the historical prices. --- .../name/abuchen/portfolio/PortfolioLog.java | 27 +++++++++++++++++++ .../online/impl/BinanceQuoteFeed.java | 2 +- .../online/impl/BitfinexQuoteFeed.java | 2 +- .../online/impl/CoinGeckoQuoteFeed.java | 2 +- .../impl/EODHistoricalDataQuoteFeed.java | 2 +- .../online/impl/GenericJSONQuoteFeed.java | 2 +- .../online/impl/HTMLTableQuoteFeed.java | 2 +- .../online/impl/KrakenQuoteFeed.java | 2 +- .../online/impl/YahooFinanceQuoteFeed.java | 2 +- 9 files changed, 35 insertions(+), 8 deletions(-) diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/PortfolioLog.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/PortfolioLog.java index c856e3049e..812e57998a 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/PortfolioLog.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/PortfolioLog.java @@ -57,6 +57,33 @@ public static void error(List errors) log.log(new Status(IStatus.ERROR, PLUGIN_ID, t.getMessage(), t)); } + /** + * Logs the messages of the given errors but without the full stack trace. + * Instead, the message will include the calling class name only. This is + * useful for common error messages which occur as part of the price + * updates. + */ + public static void abbreviated(List errors) + { + StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); + Class callerClass = walker.getCallerClass(); + + ILog log = Platform.getLog(FrameworkUtil.getBundle(PortfolioLog.class)); + for (Throwable t : errors) + log.log(new Status(IStatus.ERROR, PLUGIN_ID, "[" + callerClass.getSimpleName() + "] " + t.getMessage())); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /** + * Logs the message of the given error but without the full stack trace. + * Instead, the message will include the calling class name only. This is + * useful for common error messages which occur as part of the price + * updates. + */ + public static void abbreviated(Throwable error) + { + abbreviated(List.of(error)); + } + /** * Logs the given error message to the application log. * diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/BinanceQuoteFeed.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/BinanceQuoteFeed.java index 9d756cad34..2ccb795514 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/BinanceQuoteFeed.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/BinanceQuoteFeed.java @@ -47,7 +47,7 @@ public Optional getLatestQuote(Security security) QuoteFeedData data = getHistoricalQuotes(security, false, LocalDate.now()); if (!data.getErrors().isEmpty()) - PortfolioLog.error(data.getErrors()); + PortfolioLog.abbreviated(data.getErrors()); List prices = data.getLatestPrices(); diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/BitfinexQuoteFeed.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/BitfinexQuoteFeed.java index 3c7e06ed48..69dd4abba3 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/BitfinexQuoteFeed.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/BitfinexQuoteFeed.java @@ -47,7 +47,7 @@ public Optional getLatestQuote(Security security) QuoteFeedData data = getHistoricalQuotes(security, false, LocalDate.now()); if (!data.getErrors().isEmpty()) - PortfolioLog.error(data.getErrors()); + PortfolioLog.abbreviated(data.getErrors()); List prices = data.getLatestPrices(); diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/CoinGeckoQuoteFeed.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/CoinGeckoQuoteFeed.java index 3d5bf462d3..113d4824ef 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/CoinGeckoQuoteFeed.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/CoinGeckoQuoteFeed.java @@ -102,7 +102,7 @@ public Optional getLatestQuote(Security security) QuoteFeedData data = getHistoricalQuotes(security, false, LocalDate.now()); if (!data.getErrors().isEmpty()) - PortfolioLog.error(data.getErrors()); + PortfolioLog.abbreviated(data.getErrors()); List prices = data.getLatestPrices(); diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/EODHistoricalDataQuoteFeed.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/EODHistoricalDataQuoteFeed.java index 9f4081d475..3444dae520 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/EODHistoricalDataQuoteFeed.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/EODHistoricalDataQuoteFeed.java @@ -51,7 +51,7 @@ public Optional getLatestQuote(Security security) QuoteFeedData data = getHistoricalQuotes(security, false, LocalDate.now().minusDays(5)); if (!data.getErrors().isEmpty()) - PortfolioLog.error(data.getErrors()); + PortfolioLog.abbreviated(data.getErrors()); List prices = data.getLatestPrices(); if (prices.isEmpty()) diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/GenericJSONQuoteFeed.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/GenericJSONQuoteFeed.java index 1fa207ff9e..facef18ca5 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/GenericJSONQuoteFeed.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/GenericJSONQuoteFeed.java @@ -190,7 +190,7 @@ public Optional getLatestQuote(Security security) QuoteFeedData data = getHistoricalQuotes(security, security.getLatestFeedURL(), false, false, true); if (!data.getErrors().isEmpty()) - PortfolioLog.error(data.getErrors()); + PortfolioLog.abbreviated(data.getErrors()); List prices = data.getLatestPrices(); if (prices.isEmpty()) diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/HTMLTableQuoteFeed.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/HTMLTableQuoteFeed.java index ac5ac17131..0b5afa0840 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/HTMLTableQuoteFeed.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/HTMLTableQuoteFeed.java @@ -379,7 +379,7 @@ public Optional getLatestQuote(Security security) QuoteFeedData data = internalGetQuotes(security, feedURL, false, false); if (!data.getErrors().isEmpty()) - PortfolioLog.error(data.getErrors()); + PortfolioLog.abbreviated(data.getErrors()); List prices = data.getLatestPrices(); if (prices.isEmpty()) diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/KrakenQuoteFeed.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/KrakenQuoteFeed.java index b86e65981f..8808a9948c 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/KrakenQuoteFeed.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/KrakenQuoteFeed.java @@ -45,7 +45,7 @@ public Optional getLatestQuote(Security security) QuoteFeedData data = getHistoricalQuotes(security, false, LocalDate.now()); if (!data.getErrors().isEmpty()) - PortfolioLog.error(data.getErrors()); + PortfolioLog.abbreviated(data.getErrors()); List prices = data.getLatestPrices(); return prices.isEmpty() ? Optional.empty() : Optional.of(prices.get(prices.size() - 1)); diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/YahooFinanceQuoteFeed.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/YahooFinanceQuoteFeed.java index d1427d8d05..4a7f274ed9 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/YahooFinanceQuoteFeed.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/YahooFinanceQuoteFeed.java @@ -98,7 +98,7 @@ public Optional getLatestQuote(Security security) } catch (IOException | ParseException e) { - PortfolioLog.error(e); + PortfolioLog.abbreviated(e); return Optional.empty(); } }