aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--c_src/mysqlerl.c6
-rw-r--r--src/mysqlerl_connection.erl2
2 files changed, 6 insertions, 2 deletions
diff --git a/c_src/mysqlerl.c b/c_src/mysqlerl.c
index 5c67517..37be2e4 100644
--- a/c_src/mysqlerl.c
+++ b/c_src/mysqlerl.c
@@ -248,8 +248,10 @@ handle_connect(ETERM *msg)
logmsg("INFO: Connecting to %s on %s:%d as %s", db_name, host, port, user);
if (mysql_real_connect(&dbh, host, user, passwd,
db_name, port, NULL, 0) == NULL) {
- logmsg("ERROR: Failed to connect to database %s as %s: %s.",
- db_name, user, mysql_error(&dbh));
+ resp = erl_format("{error, {mysql_error, ~i, ~s}}",
+ mysql_errno(&dbh), mysql_error(&dbh));
+ write_msg(resp);
+ erl_free_term(resp);
exit(2);
}
diff --git a/src/mysqlerl_connection.erl b/src/mysqlerl_connection.erl
index 46d9fd3..bfff97d 100644
--- a/src/mysqlerl_connection.erl
+++ b/src/mysqlerl_connection.erl
@@ -37,6 +37,8 @@ init([Owner, Host, Port, Database, User, Password, Options]) ->
case send_port_cmd(Ref, ConnectArgs, ?CONNECT_TIMEOUT) of
{data, ok} ->
{ok, #state{port = Ref, owner = Owner}};
+ {data, {error, Error}} ->
+ {stop, Error};
{'EXIT', Ref, Reason} ->
{stop, {port_closed, Reason}}
end.