MySQLdb1 icon indicating copy to clipboard operation
MySQLdb1 copied to clipboard

Improve error message for when read_default_file doesn't exist

Open KentShikama opened this issue 7 years ago • 0 comments

Currently if you specify a read_default_file that has a different path, you'll receive the same error message as if you simply tried _mysql.connect() without any args as follows:

db=_mysql.connect(read_default_file="/bad/path/mysql.cnf")
*** _mysql_exceptions.OperationalError: (1045, "Access denied for user '<user>'@'localhost' (using password: NO)")

It would be helpful if it gave the same error message as the default mysql program as follows:

$ mysql --defaults-file=/bad/path/mysql.cnf
mysql: [ERROR] Could not open required defaults file: /bad/path/mysql.cnf
mysql: [ERROR] Fatal error in defaults handling. Program aborted!

While this might sound obvious when dealing with just db=_mysql.connect(read_default_file="/bad/path/mysql.cnf"), it becomes a little harder to catch downstream in projects like Django. For example, the following Stackoverflow question would probably have been automatically resolved if it had this error message: https://stackoverflow.com/q/45818506/2750819 .

KentShikama avatar Aug 22 '17 14:08 KentShikama