PyHive icon indicating copy to clipboard operation
PyHive copied to clipboard

Pretty print error messages

Open thoralf-gutierrez opened this issue 6 years ago • 3 comments

See issue https://github.com/dropbox/PyHive/issues/241

This makes sure that dictionaries errors (such as Presto DatabaseErrors) are printed nicely while other errors are printed as usual.

The following error

DatabaseError: {'errorName': 'SYNTAX_ERROR', 'errorType': 'USER_ERROR', 'errorLocation': {'columnNumber': 15, 'lineNumber': 1}, 'errorCode': 1, 'failureInfo': {'suppressed': [], 'type': 'com.facebook.presto.sql.analyzer.SemanticException', 'errorLocation': {'columnNumber': 15, 'lineNumber': 1}, 'stack': ['com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitTable(StatementAnalyzer.java:838)', 'com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitTable(StatementAnalyzer.java:257)', 'com.facebook.presto.sql.tree.Table.accept(Table.java:53)', 'com.facebook.presto.sql.tree.AstVisitor.process(AstVisitor.java:27)', 'com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:269)', 'com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.analyzeFrom(StatementAnalyzer.java:1787)', 'com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitQuerySpecification(StatementAnalyzer.java:944)', 'com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitQuerySpecification(StatementAnalyzer.java:257)', 'com.facebook.presto.sql.tree.QuerySpecification.accept(QuerySpecification.java:127)', 'com.facebook.presto.sql.tree.AstVisitor.process(AstVisitor.java:27)', 'com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:269)', 'com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:279)', 'com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitQuery(StatementAnalyzer.java:675)', 'com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitQuery(StatementAnalyzer.java:257)', 'com.facebook.presto.sql.tree.Query.accept(Query.java:94)', 'com.facebook.presto.sql.tree.AstVisitor.process(AstVisitor.java:27)', 'com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:269)', 'com.facebook.presto.sql.analyzer.StatementAnalyzer.analyze(StatementAnalyzer.java:243)', 'com.facebook.presto.sql.analyzer.Analyzer.analyze(Analyzer.java:72)', 'com.facebook.presto.sql.analyzer.Analyzer.analyze(Analyzer.java:64)', 'com.facebook.presto.execution.SqlQueryExecution.<init>(SqlQueryExecution.java:169)', 'com.facebook.presto.execution.SqlQueryExecution$SqlQueryExecutionFactory.createQueryExecution(SqlQueryExecution.java:677)', 'com.facebook.presto.execution.SqlQueryManager.createQueryInternal(SqlQueryManager.java:439)', 'com.facebook.presto.execution.SqlQueryManager.lambda$createQuery$3(SqlQueryManager.java:372)', 'java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)', 'java.util.concurrent.FutureTask.run(FutureTask.java:266)', 'java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)', 'java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)', 'java.lang.Thread.run(Thread.java:748)'], 'message': 'line 1:15: Table foo.bar.xyz does not exist'}, 'message': 'line 1:15: Table foo.bar.xyz does not exist'}

becomes

 DatabaseError: {
    "errorName": "SYNTAX_ERROR",
    "errorType": "USER_ERROR",
    "errorLocation": {
        "columnNumber": 15,
        "lineNumber": 1
    },
    "errorCode": 1,
    "failureInfo": {
        "suppressed": [],
        "type": "com.facebook.presto.sql.analyzer.SemanticException",
        "errorLocation": {
            "columnNumber": 15,
            "lineNumber": 1
        },
        "stack": [
            "com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitTable(StatementAnalyzer.java:838)",
            "com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitTable(StatementAnalyzer.java:257)",
            "com.facebook.presto.sql.tree.Table.accept(Table.java:53)",
            "com.facebook.presto.sql.tree.AstVisitor.process(AstVisitor.java:27)",
            "com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:269)",
            "com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.analyzeFrom(StatementAnalyzer.java:1787)",
            "com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitQuerySpecification(StatementAnalyzer.java:944)",
            "com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitQuerySpecification(StatementAnalyzer.java:257)",
            "com.facebook.presto.sql.tree.QuerySpecification.accept(QuerySpecification.java:127)",
            "com.facebook.presto.sql.tree.AstVisitor.process(AstVisitor.java:27)",
            "com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:269)",
            "com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:279)",
            "com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitQuery(StatementAnalyzer.java:675)",
            "com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.visitQuery(StatementAnalyzer.java:257)",
            "com.facebook.presto.sql.tree.Query.accept(Query.java:94)",
            "com.facebook.presto.sql.tree.AstVisitor.process(AstVisitor.java:27)",
            "com.facebook.presto.sql.analyzer.StatementAnalyzer$Visitor.process(StatementAnalyzer.java:269)",
            "com.facebook.presto.sql.analyzer.StatementAnalyzer.analyze(StatementAnalyzer.java:243)",
            "com.facebook.presto.sql.analyzer.Analyzer.analyze(Analyzer.java:72)",
            "com.facebook.presto.sql.analyzer.Analyzer.analyze(Analyzer.java:64)",
            "com.facebook.presto.execution.SqlQueryExecution.<init>(SqlQueryExecution.java:169)",
            "com.facebook.presto.execution.SqlQueryExecution$SqlQueryExecutionFactory.createQueryExecution(SqlQueryExecution.java:677)",
            "com.facebook.presto.execution.SqlQueryManager.createQueryInternal(SqlQueryManager.java:439)",
            "com.facebook.presto.execution.SqlQueryManager.lambda$createQuery$3(SqlQueryManager.java:372)",
            "java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)",
            "java.util.concurrent.FutureTask.run(FutureTask.java:266)",
            "java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)",
            "java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)",
            "java.lang.Thread.run(Thread.java:748)"
        ],
        "message": "line 1:15: Table foo.bar.xyz does not exist"
    },
    "message": "line 1:15: Table foo.bar.xyz does not exist"
}

thoralf-gutierrez avatar Oct 01 '18 19:10 thoralf-gutierrez

Codecov Report

Merging #242 into master will increase coverage by 0.06%. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #242      +/-   ##
========================================
+ Coverage   93.94%    94%   +0.06%     
========================================
  Files          14     15       +1     
  Lines        1487   1502      +15     
  Branches      159    160       +1     
========================================
+ Hits         1397   1412      +15     
  Misses         64     64              
  Partials       26     26
Impacted Files Coverage Δ
pyhive/exc.py 100% <100%> (ø) :arrow_up:
pyhive/tests/test_exc.py 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d19cb0c...25761e4. Read the comment docs.

codecov-io avatar Oct 01 '18 19:10 codecov-io

It would be really useful to have this merged to master. We currently parse the exceptions manually to provide a pretty print digested error log. Is there any reason for this not be merged?

lucharo avatar Mar 18 '21 18:03 lucharo

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Apr 16 '22 21:04 CLAassistant