From 62068ae5614d0de58ce5cf5951307ba309dbb01a Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov <ivadmi5@gmail.com> Date: Sat, 29 Jul 2023 00:28:36 +0300 Subject: [PATCH] fix: `picodata connect` eats error logs and exit codes --- src/connect.lua | 25 +++++++++++++------------ test/int/test_cli_connect.py | 6 ++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/connect.lua b/src/connect.lua index 35f70302c3..57b76661cf 100644 --- a/src/connect.lua +++ b/src/connect.lua @@ -1,22 +1,23 @@ local console = require("console") +local uri = ... + local TIMEOUT_INFINITY = 100 * 365 * 86400 -local arg = ... +local opts = {} +opts.timeout = TIMEOUT_INFINITY console.on_start(function(self) local status, reason - status, reason = pcall( - console.connect, - arg, - {connect_timeout = TIMEOUT_INFINITY} - ) + status, reason = pcall(console.connect, uri, opts) if not status then - self:print(reason) - os.exit(0) + -- `type(reason) == cdata`, so we have to convert it + self:print(tostring(reason)) + os.exit(1) end -end) - -console.on_client_disconnect(function(_) - os.exit(0) + -- We should only set this after we try to connect, because + -- `console.connect` will call this before throwing eval errors + console.on_client_disconnect(function(_) + os.exit(0) + end) end) return console.start() diff --git a/test/int/test_cli_connect.py b/test/int/test_cli_connect.py index d4d5ed41f9..411c822c67 100644 --- a/test/int/test_cli_connect.py +++ b/test/int/test_cli_connect.py @@ -124,8 +124,7 @@ def test_wrong_pass(i1: Instance): cli.expect_exact("Enter password for testuser: ") cli.sendline("badpass") - # FIXME: https://git.picodata.io/picodata/picodata/picodata/-/issues/247 - cli.expect_exact("attempt to call method 'endswith' (a nil value)") + cli.expect_exact("Connection is not established") cli.expect_exact(pexpect.EOF) @@ -161,6 +160,5 @@ def test_connection_refused(binary_path: str): cli.expect_exact("Enter password for testuser: ") cli.sendline("") - # FIXME: https://git.picodata.io/picodata/picodata/picodata/-/issues/247 - cli.expect_exact("attempt to call method 'endswith' (a nil value)") + cli.expect_exact("Connection is not established") cli.expect_exact(pexpect.EOF) -- GitLab