edgedb / edgedb-rust

The official Rust binding for EdgeDB
https://edgedb.com
Apache License 2.0
208 stars 26 forks source link

Refine error output if ErrorResponse received #279

Closed Dhghomon closed 9 months ago

Dhghomon commented 10 months ago

Looks like the resolution to this issue https://github.com/edgedb/edgedb-cli/issues/1125 is inside edgedb-rust (and edgedb itself).

This PR essentially changes this:

[2023-09-26T02:24:30Z WARN edgedb_tokio::raw::connection] Error received from server: database 'edgedbb' does not exist. Severity: Error. Code: 67305477[2023-09-26T02:24:30Z DEBUG edgedb_tokio::raw::connection] Error details: {257: b"Traceback (most recent call last):\n File \"edb/server/dbview/dbview.pyx\", line 1182, in edb.server.dbview.dbview.DatabaseIndex.get_db\nKeyError: 'edgedbb'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"edb/server/protocol/frontend.pyx\", line 294, in edb.server.protocol.frontend.FrontendConnection.main\n File \"edb/server/protocol/binary.pyx\", line 1022, in authenticate\n File \"edb/server/protocol/binary.pyx\", line 292, in auth\n File \"edb/server/protocol/binary.pyx\", line 385, in _start_connection\n File \"/home/edgedb/.local/share/edgedb/portable/3.3/lib/python3.11/site-packages/edb/server/server.py\", line 621, in new_dbview\n db = self.get_db(dbname=dbname)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/edgedb/.local/share/edgedb/portable/3.3/lib/python3.11/site-packages/edb/server/server.py\", line 614, in get_db\n return self._dbindex.get_db(dbname)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"edb/server/dbview/dbview.pyx\", line 1184, in edb.server.dbview.dbview.DatabaseIndex.get_db\nedb.errors.UnknownDatabaseError: database 'edgedbb' does not exist\n"}

to this:

[2023-09-26T03:09:16Z WARN edgedb_tokio::raw::connection] Error received from server: database 'edgedbb' does not exist. Severity: Error. Code: 0x4030005

But also displays the extra output if RUST_LOG is set to at least debug.

The other part adding "please specify another one" that @1st1 mentions looks to be from here in the Python code: https://github.com/edgedb/edgedb/blob/23a7cd0f2db8d66addb0cd38950c85268f585742/edb/server/dbview/dbview.pyx#L1194 So maybe @msullivan might want to add that?

On a related point, when the CLI starts up it calls this log_levels::init() function here https://github.com/edgedb/edgedb-cli/blob/master/src/main.rs#L122 that does some pretty precise changes to the log levels depending on which command is being used and whether it's --verbose or not, so when I make a change to the CLI I always comment it out and set RUST_LOG to trace. It could be nice to make a flag to do this so everyday EdgeDB users and Rust users that don't feel like building the CLI just to see more debug output could set the log level to try to find out themselves what went wrong. Any reason not to add that flag in a different PR?

raddevon commented 10 months ago

LGTM, but I will let someone who can apply more rigor to the Rust code do a proper review.