Skip to content

Commit

Permalink
Improve data not found error messages. (#8295)
Browse files Browse the repository at this point in the history
* Improve data not found error messages.

* Minor tweaks

---------

Co-authored-by: Kevin Wheeler <[email protected]>
Co-authored-by: Martin Molinero <[email protected]>
  • Loading branch information
3 people authored Sep 20, 2024
1 parent 0b285df commit a0055a3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Common/Data/DataMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void OnNewDataRequest(object sender, DataProviderNewDataRequestEventArgs
var isUniverseData = path.Contains("coarse", StringComparison.OrdinalIgnoreCase) ||
path.Contains("universe", StringComparison.OrdinalIgnoreCase);

if (e.Succeded)
if (e.Succeeded)
{
WriteLineToFile(_succeededDataRequestsWriter, path, _succeededDataRequestsFileName);
Interlocked.Increment(ref _succeededDataRequestsCount);
Expand All @@ -105,7 +105,7 @@ public void OnNewDataRequest(object sender, DataProviderNewDataRequestEventArgs

if (Logging.Log.DebuggingEnabled)
{
Logging.Log.Debug($"DataMonitor.OnNewDataRequest(): Data from {path} could not be fetched");
Logging.Log.Debug($"DataMonitor.OnNewDataRequest(): Data from {path} could not be fetched, error: {e.ErrorMessage}");
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions Common/Interfaces/DataProviderDataFetchedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,24 @@ public class DataProviderNewDataRequestEventArgs : EventArgs
/// <summary>
/// Whether the data was fetched successfully
/// </summary>
public bool Succeded { get; }
public bool Succeeded { get; }

/// <summary>
/// Any error message that occurred during the fetch
/// </summary>
public string ErrorMessage { get; }

/// <summary>
/// Initializes a new instance of the <see cref="DataProviderNewDataRequestEventArgs"/> class
/// </summary>
/// <param name="path">The path to the fetched data</param>
/// <param name="succeded">Whether the data was fetched successfully</param>
public DataProviderNewDataRequestEventArgs(string path, bool succeded)
/// <param name="succeeded">Whether the data was fetched successfully</param>
/// <param name="errorMessage">Any error message that occured during the fetch</param>
public DataProviderNewDataRequestEventArgs(string path, bool succeeded, string errorMessage)
{
Path = path;
Succeded = succeded;
Succeeded = succeeded;
ErrorMessage = errorMessage;
}
}
}
18 changes: 15 additions & 3 deletions Engine/DataFeeds/DefaultDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace QuantConnect.Lean.Engine.DataFeeds
/// </summary>
public class DefaultDataProvider : IDataProvider, IDisposable
{
private bool _oneTimeWarningLog;

/// <summary>
/// Event raised each time data fetch is finished (successfully or not)
/// </summary>
Expand All @@ -37,15 +39,25 @@ public class DefaultDataProvider : IDataProvider, IDisposable
public virtual Stream Fetch(string key)
{
var success = true;
var errorMessage = string.Empty;
try
{
return new FileStream(FileExtension.ToNormalizedPath(key), FileMode.Open, FileAccess.Read, FileShare.Read);
}
catch (Exception exception)
{
success = false;
if (exception is DirectoryNotFoundException
|| exception is FileNotFoundException)
errorMessage = exception.Message;
if (exception is DirectoryNotFoundException)
{
if (!_oneTimeWarningLog)
{
_oneTimeWarningLog = true;
Logging.Log.Debug($"DefaultDataProvider.Fetch(): DirectoryNotFoundException: please review data paths, current 'Globals.DataFolder': {Globals.DataFolder}");
}
return null;
}
else if (exception is FileNotFoundException)
{
return null;
}
Expand All @@ -54,7 +66,7 @@ public virtual Stream Fetch(string key)
}
finally
{
OnNewDataRequest(new DataProviderNewDataRequestEventArgs(key, success));
OnNewDataRequest(new DataProviderNewDataRequestEventArgs(key, success, errorMessage));
}
}

Expand Down

0 comments on commit a0055a3

Please sign in to comment.