diff --git a/src/connect.lua b/src/connect.lua
index 35f70302c3b487e064df1d9d1a82519776b90958..57b76661cf85f3980c0817d7a9fa5b0caa02f8da 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 d4d5ed41f9d656e3512433b4d887477f627d0523..411c822c67193c40cee8c56b9b8e20c75833bcea 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)