-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This library uses STDERR instead of throwing exceptions when failures are encountered #1863
Comments
This problem appears to have always been there, but was exacerbated by the introduction of the use of logger: |
Ouch 3 points:
So logs should be kept (if their content is useful to the library's author or to the library's user, I have no opinion there as I use yfinance sporadically only), but below ERROR-level only, and errors shall be raised as exceptions indeed |
Some context on why exceptions were redirected to logger:
Argument |
That’s great @ValueRaider thx |
Describe Design Problem
This issue seems to be pervasive through the library but can be demonstrated with the below (I use pandas_datareader which wraps this library):
It'll return successfully while producing the following output:
The error output is printed to STDERR instead of yfinance throwing an exception for the consumer of the yfinance library to handle. This breaks error handling and pollutes my application's output.
Essentially this means that yfinance currently hijacks STDERR for consuming applications so that it can report errors instead of throwing an exception with the same information (using exceptions allows consuming applications to determine how failures are handled or represented).
A library should almost never write to stdout and stderr for errors -- this also has very big implications for flow control and error handling in consuming logic-- whether by an application that uses this library or another library that wraps it (such as pandas_datareader which is a very visible example).
It seems to be littered all through the library, but this code specifically exemplifies the issue:
yfinance/yfinance/base.py
Line 1687 in 1d31e7c
I think these might help clarify the reasoning here:
The text was updated successfully, but these errors were encountered: