You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Phillip B Oldham <ph...@gmail.com> on 2009/01/18 23:10:54 UTC
Empty exceptions with python server/client.
I've created a test server and client in python, and with the "fail
fast" philosophy I'm trying to get exception handling working before
everything else. Things seem to work fine in terms of starting the
server, connecting with the client and calling the remote procedures,
but the exception messages are being seen by the client as a None
object.
I'm raising exceptions as usual, and catching both the explicit type
and with the following taken from the tutorial:
except Thrift.TException, tx:
print 'Error: %s' % (tx.message)
Any ideas?
--
Phillip B Oldham
phillip.oldham@gmail.com
+44 (0) 7525 01 09 01
RE: Empty exceptions with python server/client.
Posted by Mark Slee <ms...@facebook.com>.
I believe the reason this fails may be because of how you're using the comma-notation to pass the arg to the constructor.
There were some recent changes to the Thrift Python generator -- can you paste the generated code for class NotValidException that you're using?
If it looks like this:
class NotValidException(Exception):
def __init__(self, d=None):
if isinstance(d, dict):
...
Then the issue is that you're passing a string as args, and it's not actually turning into the "why" field in your exception when your __init__ method is invoked.
If you're using the latest update to the generator, then this SHOULD work, but you'll still be better off doing:
raise NotValidException(why="thisiswhy")
-----Original Message-----
From: Phillip B Oldham [mailto:phillip.oldham@gmail.com]
Sent: Tuesday, January 20, 2009 2:43 PM
To: thrift-user@incubator.apache.org
Subject: Re: Empty exceptions with python server/client.
On Tue, Jan 20, 2009 at 10:24 PM, Mark Slee <ms...@facebook.com> wrote:
> Can you paste your code that raises the exception?
The thrift file:
exception NotValidException {
string why
}
service TestService {
bool isValid( 1:string text ) throws ( 1:NotValidException e ) }
the python server class:
class TestServiceHandler:
def isValid(self, text):
raise NotValidException, "because it isn't"
return False
the python client:
try:
try:
client.isValid("test")
catch NotValidException, e
print e.why
except Thrift.TException, tx:
print 'Error: %s' % (tx.message)
I've tried calling the exception attribute "message", I've tried various variations on the theme laid out above, but when the exception gets properly caught by either of the except blocks the message returned is None.
> Is this an exception being thrown across an RPC call at the application level?
I'm not sure I understand the question, but you will hopefully see from above what I'm trying to do.
--
Phillip B Oldham
phillip.oldham@gmail.com
+44 (0) 7525 01 09 01
Re: Empty exceptions with python server/client.
Posted by Phillip B Oldham <ph...@gmail.com>.
On Tue, Jan 20, 2009 at 10:24 PM, Mark Slee <ms...@facebook.com> wrote:
> Can you paste your code that raises the exception?
The thrift file:
exception NotValidException {
string why
}
service TestService {
bool isValid( 1:string text ) throws ( 1:NotValidException e )
}
the python server class:
class TestServiceHandler:
def isValid(self, text):
raise NotValidException, "because it isn't"
return False
the python client:
try:
try:
client.isValid("test")
catch NotValidException, e
print e.why
except Thrift.TException, tx:
print 'Error: %s' % (tx.message)
I've tried calling the exception attribute "message", I've tried
various variations on the theme laid out above, but when the exception
gets properly caught by either of the except blocks the message
returned is None.
> Is this an exception being thrown across an RPC call at the application level?
I'm not sure I understand the question, but you will hopefully see
from above what I'm trying to do.
--
Phillip B Oldham
phillip.oldham@gmail.com
+44 (0) 7525 01 09 01
RE: Empty exceptions with python server/client.
Posted by Mark Slee <ms...@facebook.com>.
Can you paste your code that raises the exception? I don't know that the message field will always be populated by default in a TException.
Is this an exception being thrown across an RPC call at the application level?
-----Original Message-----
From: Phillip B Oldham [mailto:phillip.oldham@gmail.com]
Sent: Sunday, January 18, 2009 2:11 PM
To: thrift-user@incubator.apache.org
Subject: Empty exceptions with python server/client.
I've created a test server and client in python, and with the "fail fast" philosophy I'm trying to get exception handling working before everything else. Things seem to work fine in terms of starting the server, connecting with the client and calling the remote procedures, but the exception messages are being seen by the client as a None object.
I'm raising exceptions as usual, and catching both the explicit type and with the following taken from the tutorial:
except Thrift.TException, tx:
print 'Error: %s' % (tx.message)
Any ideas?
--
Phillip B Oldham
phillip.oldham@gmail.com
+44 (0) 7525 01 09 01