Skip to content

Commit

Permalink
Show connection error message before prompting user to reconnect with…
Browse files Browse the repository at this point in the history
… \connect
  • Loading branch information
matriv committed Jul 4, 2017
1 parent b687d1f commit 4272500
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -5,6 +5,9 @@ Changes for crash
Unreleased
==========

- Show error message before prompting the user to reconnect with ``\connect``
if the ``verbose`` is set.

- Added new command ``verbose`` to be able to toggle verbosity ON & OFF from
within Crash without the need to exit and reconnect.

Expand Down
9 changes: 6 additions & 3 deletions src/crate/crash/command.py
Expand Up @@ -351,7 +351,9 @@ def _execute(self, statement):
try:
self.cursor.execute(statement)
return True
except ConnectionError:
except ConnectionError as e:
if self.error_trace:
self.logger.warn(str(e))
self.logger.warn(
'Use \connect <server> to connect to one or more servers first.')
except ProgrammingError as e:
Expand Down Expand Up @@ -485,13 +487,14 @@ def main():
cmd.exit()
sys.exit(cmd.exit_code)

def _create_cmd(crate_hosts, error_trace, output_writer, is_tty, args):
def _create_cmd(crate_hosts, error_trace, output_writer, is_tty, args, timeout=None):
conn = connect(crate_hosts,
verify_ssl_cert=args.verify_ssl,
cert_file=args.cert_file,
key_file=args.key_file,
ca_cert=args.ca_cert_file,
username=args.username)
username=args.username,
timeout=timeout)
return CrateCmd(connection=conn,
error_trace=error_trace,
output_writer=output_writer,
Expand Down
21 changes: 21 additions & 0 deletions src/crate/crash/test_command.py
Expand Up @@ -532,6 +532,27 @@ def test_wrong_host_format(self):
with self.assertRaises(LocationParseError):
_create_cmd(crate_hosts, False, None, False, args)

def test_command_timeout(self):
sys.argv = ["testcrash",
"--hosts", self.crate_host
]
parser = get_parser()
args = parse_args(parser)

crate_hosts = [host_and_port(h) for h in args.hosts]
crateCmd = _create_cmd(crate_hosts, False, None, False, args, 0.00001)
crateCmd.logger = Mock()

# without verbose
crateCmd.execute("select count(*) from sys.nodes")
crateCmd.logger.warn.assert_any_call("Use \connect <server> to connect to one or more servers first.")

# with verbose
crateCmd.error_trace = True
crateCmd.execute("select count(*) from sys.nodes")
crateCmd.logger.warn.assert_any_call("No more Servers available, exception from last server: HTTPConnectionPool(host='127.0.0.1', port=44209): Read timed out. (read timeout=1e-05)")
crateCmd.logger.warn.assert_any_call("Use \connect <server> to connect to one or more servers first.")

def test_username_param(self):
sys.argv = ["testcrash",
"--hosts", self.crate_host,
Expand Down

0 comments on commit 4272500

Please sign in to comment.