[p4python] p4python errors

Smith, Jeff jsmith at medplus.com
Fri Jul 22 07:57:53 PDT 2005


Kudos!

Thanks for the update!

Jeff

-----Original Message-----
From: Robert Cowham [mailto:robert at vaccaperna.co.uk] 
Sent: Friday, July 22, 2005 10:55 AM
To: Smith, Jeff; p4python at perforce.com
Subject: RE: [p4python] p4python errors


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: p4python-bounces at perforce.com 
> > [mailto:p4python-bounces at perforce.com] On Behalf Of Smith, Jeff
> > Sent: 21 July 2005 20:57
> > To: p4python at 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





More information about the p4python mailing list