From 1a87d5a0c0ce62fb2c42bea0793b8ee15e655868 Mon Sep 17 00:00:00 2001 From: Victor Grau Serrat Date: Thu, 12 Oct 2017 09:15:45 -0600 Subject: [PATCH] Making errors more verbose and user-friendly --- catalyst/exchange/data_portal_exchange.py | 8 +++++--- catalyst/exchange/exchange_errors.py | 12 +++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/catalyst/exchange/data_portal_exchange.py b/catalyst/exchange/data_portal_exchange.py index e47ca435..fe9acd09 100644 --- a/catalyst/exchange/data_portal_exchange.py +++ b/catalyst/exchange/data_portal_exchange.py @@ -311,7 +311,7 @@ class DataPortalExchangeBacktest(DataPortalExchangeBase): field=field, first_trading_day=self._get_first_trading_day(assets), exchange=exchange.name, - symbols=[asset.symbol for asset in assets], + symbols=[asset.symbol.encode('utf-8') for asset in assets], ) series = dict() @@ -332,7 +332,8 @@ class DataPortalExchangeBacktest(DataPortalExchangeBase): raise PricingDataBeforeTradingError( first_trading_day=first_trading_day, exchange=assets[0].exchange, - symbols=[asset.symbol for asset in assets], + symbols=[asset.symbol.encode('utf-8') for asset in assets], + dt = dt, ) def get_exchange_spot_value(self, exchange, assets, field, dt, @@ -356,7 +357,8 @@ class DataPortalExchangeBacktest(DataPortalExchangeBase): field=field, first_trading_day=self._get_first_trading_day(assets), exchange=exchange.name, - symbols=[asset.symbol for asset in assets], + symbols=[asset.symbol.encode('utf-8') for asset in assets], + symbol_list = ''.join([asset.symbol.encode('utf-8') for asset in assets]) ) return values diff --git a/catalyst/exchange/exchange_errors.py b/catalyst/exchange/exchange_errors.py index b6716228..fc54ec9b 100644 --- a/catalyst/exchange/exchange_errors.py +++ b/catalyst/exchange/exchange_errors.py @@ -2,11 +2,12 @@ import sys, traceback from catalyst.errors import ZiplineError def silent_except_hook(exctype, excvalue, exctraceback): - if exctype in [SymbolNotFoundOnExchange,]: + if exctype in [ PricingDataBeforeTradingError, PricingDataNotLoadedError, + SymbolNotFoundOnExchange, ]: fn = traceback.extract_tb(exctraceback)[-1][0] ln = traceback.extract_tb(exctraceback)[-1][1] print "Error traceback: {1} (line {2})\n" \ - "{0.__name__}: {3}.".format(exctype, fn, ln, excvalue) + "{0.__name__}: {3}".format(exctype, fn, ln, excvalue) else: sys.__excepthook__(exctype, excvalue, exctraceback) @@ -169,15 +170,16 @@ class BundleNotFoundError(ZiplineError): class PricingDataBeforeTradingError(ZiplineError): msg = ('Pricing data for trading pairs {symbols} on exchange {exchange} ' - 'starts on {first_trading_day}.').strip() + 'starts on {first_trading_day}, but you are either trying to trade or ' + 'retrieve pricing data on {dt}. Adjust your dates accordingly.').strip() class PricingDataNotLoadedError(ZiplineError): msg = ('Pricing data {field} for trading pairs {symbols} trading on ' 'exchange {exchange} since {first_trading_day} is unavailable. ' - 'The bundle data is either out-of-date or has not been loaded yet.' + 'The bundle data is either out-of-date or has not been loaded yet. ' 'Please ingest data using the command ' - '`catalyst ingest -b exchange_{exchange}`. ' + '`catalyst ingest-exchange -x {exchange} -i {symbol_list}`. ' 'See catalyst documentation for details.').strip()