4 messages in com.perforce.p4python[p4python] p4python errors
FromSent OnAttachments
Smith, Jeff21 Jul 2005 12:57 
Robert Cowham22 Jul 2005 00:59 
Robert Cowham22 Jul 2005 07:55 
Smith, Jeff22 Jul 2005 07:57 
Subject:[p4python] p4python errors
From:Robert Cowham (rob@vaccaperna.co.uk)
Date:07/22/2005 07:55:00 AM
List:com.perforce.p4python

OK I have just released 0.6.

From CHANGELOG.txt:

- Added P4Error class and catch all errors - shouldn't see P4Client.error any more! - Raise the error when appropriate. - Added translate() function to allow working with Internationalised servers. - Fix problem with diff2 and diff

Thus the following works out of the box:

import p4 p4c = p4.P4() p4c.run_info()

Traceback (most recent call last): File "<stdin>", line 1, in ? File "C:\Python24\Lib\site-packages\p4.py", line 132, in run raise P4Error(msg) p4.P4Error: Can't run a command without running connect() first

p4c.run_login("-s")

Traceback (most recent call last): File "<stdin>", line 1, in ? File "C:\Python24\Lib\site-packages\p4.py", line 166, in run raise P4Error(string.join(self.errors, "\n")) p4.P4Error: Password must be set before access can be granted.

p4c.port = "1234.1324.1243.1324:1213" p4c.connect()

Traceback (most recent call last): File "<stdin>", line 1, in ? File "C:\Python24\Lib\site-packages\p4.py", line 282, in connect return self.p4client.connect() File "C:\Python24\Lib\site-packages\p4.py", line 75, in connect raise P4Error(str(e)) p4.P4Error: Connect to server failed; check $P4PORT. TCP connect to 1234.1324.1243.1324:1213 failed. connect: 1234.1324.1243.1324:1213: WSAEADDRNOTAVAIL

So for the error string you can either look in the exception itself or p4.errors:

Try: p4c.run(somcmd) Except p4.P4Error, e: print str(e)

Or

Try: p4c.run(somcmd) Except p4.P4Error: for e in p4c.errors: print e

Comments welcome.

Note also the new .login() and .passwd() shortcut functions.

Regards Robert

-----Original Message----- From: p4py@perforce.com [mailto:p4py@perforce.com] On Behalf Of Smith, Jeff Sent: 21 July 2005 20:57 To: p4py@perforce.com Subject: [p4python] p4python errors

I notice that sometimes p4python throws class type errors whereas other times it throws strings as errors. This makes it ugly to catch all possible p4python errors and requires something akin to:

try: client.method() except p4.P4Client.error: handle_this except: if client.errors: handle_this else: raise

and even this won't catch everything since sometimes client.errors is empty

Is anyone else seeing this?

Jeff Python 2.4 p4python 0.5