Skip to content

Commit

Permalink
Add rbmsg back to TRILOGY_ERR (#187)
Browse files Browse the repository at this point in the history
This was previously [removed][1] when error classes were refactored, but
it doesn't seem to have been done so intentionally.

When debugging a previous [fix][2], this missing context would have
helped narrow down the problem initially as the rbmsg includes where the
error was originating.

[1]: f9ee855
[2]: cb788be
  • Loading branch information
skipkayhil authored Jul 23, 2024
1 parent 0a18015 commit e84501b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion contrib/ruby/ext/trilogy-ruby/cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ static void handle_trilogy_error(struct trilogy_ctx *ctx, int rc, const char *ms
rb_raise(Trilogy_TimeoutError, "%" PRIsVALUE, rbmsg);

case TRILOGY_ERR: {
VALUE message = rb_str_new(ctx->conn.error_message, ctx->conn.error_message_len);
VALUE conn_message = rb_str_new(ctx->conn.error_message, ctx->conn.error_message_len);
VALUE message = rb_sprintf("%" PRIsVALUE " (%" PRIsVALUE ")", conn_message, rbmsg);
VALUE exc = rb_funcall(Trilogy_ProtocolError, id_from_code, 2, message, INT2NUM(ctx->conn.error_code));
rb_exc_raise(exc);
}
Expand Down
3 changes: 3 additions & 0 deletions contrib/ruby/test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def test_trilogy_set_server_option_with_invalid_option

assert_instance_of(Trilogy::ProtocolError, e)
assert_match(/1047: Unknown command/, e.message)
assert_match(/trilogy_set_option_recv/, e.message)
end

def test_trilogy_set_server_option_multi_statement
Expand All @@ -283,6 +284,7 @@ def test_trilogy_set_server_option_multi_statement

assert_instance_of(Trilogy::QueryError, e)
assert_match(/1064: You have an error in your SQL syntax/, e.message)
assert_match(/trilogy_query_recv/, e.message)

client.set_server_option(Trilogy::SET_SERVER_MULTI_STATEMENTS_ON)
client.query("INSERT INTO trilogy_test (int_test) VALUES ('4'); INSERT INTO trilogy_test (int_test) VALUES ('1')")
Expand All @@ -301,6 +303,7 @@ def test_trilogy_set_server_option_multi_statement

assert_instance_of(Trilogy::QueryError, e)
assert_match(/1064: You have an error in your SQL syntax/, e.message)
assert_match(/trilogy_query_recv/, e.message)
end

def test_trilogy_query_result_object
Expand Down

0 comments on commit e84501b

Please sign in to comment.