Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exceptions #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add exceptions #20

wants to merge 3 commits into from

Conversation

scohen
Copy link
Collaborator

@scohen scohen commented Apr 12, 2016

This PR adds exceptions to the client, server and struct modules. It's dependent on thrift 0.10 though, and targets the 1.5 branch.

@scohen
Copy link
Collaborator Author

scohen commented Apr 12, 2016

@laozhp @tbug How is this?

@scohen scohen mentioned this pull request Apr 12, 2016
@jparise
Copy link
Collaborator

jparise commented Apr 12, 2016

Maybe this should require Thrift 0.10 in mix.exs (via thrift_version).

The .travis.yml script will also need to an update to use Thrift 0.10 in the CI environment.

@laozhp
Copy link

laozhp commented Apr 13, 2016

Good job! I had found the generated struct_names() not include exception names, so I add a PR(apache/thrift#975) to thrift compiler to generate exception_names() meta info.

@scohen
Copy link
Collaborator Author

scohen commented Apr 13, 2016

@jparise I can't, it's not out yet.

@laozhp Thanks for putting that fix in; I'm sad to say that I omitted exceptions when I made the original change. Once this lands, I can just ask for the exceptions rather than relying on them not being in the struct list.

@tudborg
Copy link

tudborg commented Apr 20, 2016

Sorry for not getting back sooner.
I'll take a look at this asap, but at first glance it looks great 👍

@tudborg
Copy link

tudborg commented May 17, 2016

Ah, sorry for not getting back.
I'm having trouble building thrift 0.10, havn't had time to debug the issue yet.

@scohen
Copy link
Collaborator Author

scohen commented May 18, 2016

@tbug apparently, so is apache ;)

To say we're disappointed with the speed of thrift releases is an understatement.

@tudborg
Copy link

tudborg commented May 18, 2016

@scohen Ha, alright. I guess I'm happy it's not just me then 😄

I'm not really following thrift dev, so I have no idea how far we are from 0.10,
but I'd expect it to be around the corner?
Out of curiosity, which parts of this PR depends on 0.10?

@scohen
Copy link
Collaborator Author

scohen commented May 18, 2016

@tbug As far as I can tell from the outside, they've tagged the release and are now doing... something.

This PR relies on deeper metadata around functions and exceptions, which were added to 0.10.

@@ -209,6 +248,8 @@ defmodule Riffed.Client do
call_thrift(new_client, call_name, args, retry_count + 1)
err = {:error, _} ->
{new_client, err}
exception = {:exception, exception_record} ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found that this isn't enough to catch the exception.. The actual erlang thrift client will throw the exception, not just return it. So when working with services that go through the thrift client (maybe the tests here don't?), the GenServer will EXIT before we reach this case statement

https://github.com/apache/thrift/blob/master/lib/erl/src/thrift_client.erl#L150

        [Exception] ->
            throw({NewClient, {exception, Exception}})

I had to modify the :thrift_client.call to look something like this:

        {thrift_client, response} = try do
          :thrift_client.call(client.client, call_name, args)
        catch
          exception_response = {thrift_client, {:exception, exception}} -> exception_response
        end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@binaryseed is this the behavior in 0.9.3 or in head? They made a bunch of changes in head (and in the forever-upcoming 0.10 release)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so, the code I reference is in master and I'm running based of a fork of elixir-thrift that points at master, not 0.9.3

Thrift now raises exceptions, which is now handled correctly and tested.
@scohen
Copy link
Collaborator Author

scohen commented Aug 31, 2016

@binaryseed Sorry it's been so long, but I updated exception handling on the v1_5_0 branch. Please give it a shot.
I also made full end-to-end unit tests so that I can be sure that both the server and client handle exceptions properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants