forked from catherinedevlin/ipython-sql
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test Lint changelog util moved error_message sqlglot conflicts tests postgres Error changed import added detail in connection added detail in connection test fix Error msg modified More tests changelog merge conflicts Review cmts Exceptions usageerror Doc note changelog printing ploomber link printing ploomber link err msg changed Review comments Integration test Error msg postgres test runtimeerror Empty commit sqlalchemy version ci fix test ci fix test moved modify_exceptions skipping failing tests Disabled modify_exception fixed tests revert changes Revert xfail ipython usageerror comment comment Empty commit Fix removed skip win fix ipython removed setup changed exception drop table error msg sq brackets format fixed test Empty-Commit rebase func naming Revert xfail moved strings duckdb tests changelog File renamed Integration tests Lint Lint err msg assert Generic db Revert test revert space integration revert sqlparse added original msg tests original in connection tests modified test fix redundant str
- Loading branch information
1 parent
87dce34
commit 536cadc
Showing
11 changed files
with
354 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sqlglot | ||
import sqlparse | ||
|
||
SYNTAX_ERROR = "\nLooks like there is a syntax error in your query." | ||
ORIGINAL_ERROR = "\nOriginal error message from DB driver:\n" | ||
|
||
|
||
def detail(original_error, query=None): | ||
original_error = str(original_error) | ||
return_msg = SYNTAX_ERROR | ||
if "syntax error" in original_error: | ||
query_list = sqlparse.split(query) | ||
for q in query_list: | ||
try: | ||
q = q.strip() | ||
q = q[:-1] if q.endswith(";") else q | ||
parse = sqlglot.transpile(q) | ||
suggestions = "" | ||
if q.upper() not in [suggestion.upper() for suggestion in parse]: | ||
suggestions += f"Did you mean : {parse}\n" | ||
return_msg = ( | ||
return_msg + "Possible reason: \n" + suggestions | ||
if suggestions | ||
else return_msg | ||
) | ||
|
||
except sqlglot.errors.ParseError as e: | ||
err = e.errors | ||
position = "" | ||
for item in err: | ||
position += ( | ||
f"Syntax Error in {q}: {item['description']} at " | ||
f"Line {item['line']}, Column {item['col']}\n" | ||
) | ||
return_msg = ( | ||
return_msg + "Possible reason: \n" + position | ||
if position | ||
else return_msg | ||
) | ||
|
||
return return_msg + "\n" + ORIGINAL_ERROR + original_error + "\n" | ||
|
||
if "fe_sendauth: no password supplied" in original_error: | ||
return ( | ||
"\nLooks like you have run into some issues. " | ||
"Review our DB connection via URL strings guide: " | ||
"https://jupysql.ploomber.io/en/latest/connecting.html ." | ||
" Using Ubuntu? Check out this guide: " | ||
"https://help.ubuntu.com/community/PostgreSQL#fe_sendauth:_" | ||
"no_password_supplied\n" + ORIGINAL_ERROR + original_error + "\n" | ||
) | ||
|
||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.