Skip to content

Commit

Permalink
Abbreviate error message when updating historical prices
Browse files Browse the repository at this point in the history
Reduce the pollution of stack trace in the log for common error messages
that occur during the update of the historical prices.
  • Loading branch information
buchen committed Mar 1, 2024
1 parent b618f02 commit 500a65a
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ public static void error(List<? extends Throwable> 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<? extends Throwable> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Optional<LatestSecurityPrice> getLatestQuote(Security security)
QuoteFeedData data = getHistoricalQuotes(security, false, LocalDate.now());

if (!data.getErrors().isEmpty())
PortfolioLog.error(data.getErrors());
PortfolioLog.abbreviated(data.getErrors());

List<LatestSecurityPrice> prices = data.getLatestPrices();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Optional<LatestSecurityPrice> getLatestQuote(Security security)
QuoteFeedData data = getHistoricalQuotes(security, false, LocalDate.now());

if (!data.getErrors().isEmpty())
PortfolioLog.error(data.getErrors());
PortfolioLog.abbreviated(data.getErrors());

List<LatestSecurityPrice> prices = data.getLatestPrices();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Optional<LatestSecurityPrice> getLatestQuote(Security security)
QuoteFeedData data = getHistoricalQuotes(security, false, LocalDate.now());

if (!data.getErrors().isEmpty())
PortfolioLog.error(data.getErrors());
PortfolioLog.abbreviated(data.getErrors());

List<LatestSecurityPrice> prices = data.getLatestPrices();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Optional<LatestSecurityPrice> 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<LatestSecurityPrice> prices = data.getLatestPrices();
if (prices.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public Optional<LatestSecurityPrice> 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<LatestSecurityPrice> prices = data.getLatestPrices();
if (prices.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public Optional<LatestSecurityPrice> getLatestQuote(Security security)
QuoteFeedData data = internalGetQuotes(security, feedURL, false, false);

if (!data.getErrors().isEmpty())
PortfolioLog.error(data.getErrors());
PortfolioLog.abbreviated(data.getErrors());

List<LatestSecurityPrice> prices = data.getLatestPrices();
if (prices.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Optional<LatestSecurityPrice> getLatestQuote(Security security)
QuoteFeedData data = getHistoricalQuotes(security, false, LocalDate.now());

if (!data.getErrors().isEmpty())
PortfolioLog.error(data.getErrors());
PortfolioLog.abbreviated(data.getErrors());

List<LatestSecurityPrice> prices = data.getLatestPrices();
return prices.isEmpty() ? Optional.empty() : Optional.of(prices.get(prices.size() - 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Optional<LatestSecurityPrice> getLatestQuote(Security security)
}
catch (IOException | ParseException e)
{
PortfolioLog.error(e);
PortfolioLog.abbreviated(e);
return Optional.empty();
}
}
Expand Down

0 comments on commit 500a65a

Please sign in to comment.